Demo Script

Using the Worker Role

Lab version:2.0.0

Last updated:10/16/2018

Contents

Overview

Key Messages

Key Technologies

Time Estimates

Setup and Configuration

Task 1 –Run the dependency checker

Demo Flow

Opening Statement

Step-by-Step Walkthrough

Reviewing the worker role code

Summary

Overview

This document provides setup documentation, step-by-step instructions, and a written script for showing a demo of Windows Azure. This document can also serve as a tutorial or walkthrough of the technology. In this demoyou will demonstrate the basic components of a worker role. The project is provided, and there are no coding steps. For additional demos of the Azure Services Platform, please visit

Note: You do not need internet connectivity for this demo as everything is performed locally.

Key Messages

In this demo you will see three things:

  1. You will see that Windows Azure can host other languages other than C#
  2. You will learn that worker roles are simple class libraries, with a class inheriting from RoleEntryPoint. Think of workers as a console application, or a Windows Service.
  3. You will see the interaction points used by the fabric to start, stop and get the health status.

Key Technologies

This demo uses the following technologies:

  1. .NET Framework 4
  2. Visual Studio 2010
  3. Windows Azure SDK
  4. Windows Azure Tools for Microsoft Visual Studio
  5. Windows Azure Services

Time Estimates

  • Estimated time for setting up and configuring the demo: 10 min
  • Estimated time to complete the demo: 10 min

Setup and Configuration

This demo does not have any advanced configuration requirements. You simply need to have the pre-requisites installed and have a developer account for Windows Azure.

Task 1 –Run the dependency checker

The following steps describe how to run the Dependency Checker utility included with the lab to verify that you have the pre-requisite components properly installed. You can skip this exercise if you are confident that the pre-requisitesare properly installed and configured.

  1. Run the StartHere.cmd command script located in the directory that contains this demo.
  2. The StartHere.cmd script will launch the Configuration Wizard. The Configuration Wizard is designed to check your machine to ensure that it is properly configured with all of the dependencies to build and use the Azure Services Platform Management Tools.
  3. Click through the steps in the Configuration Wizard. The Required Software step will perform the actual scan of your machine. If you do not have the necessary dependencies, then install them using the links provided by the dependency checker and rescan your machine.

Demo Flow

The following diagram illustrates the high-level flow for this demo and the steps involved:

Figure 1

Demo Flow

Opening Statement

In the next few minutes we’ll take a look at how you can implement a worker role. In the interests of time, we will examine an existing worker role in the Guestbook service.

In this demo you will specifically see three things:

  1. You will see that Windows Azure can host other languages other than C#
  2. You will learn that worker roles are simple class libraries, with a class inheriting from RoleEntryPoint. Think of workers as a console application, or a Windows Service.
  3. You will see the interaction points used by the fabric to start, stop and get the health status.

Step-by-Step Walkthrough

This demo is composed of the following segments:

  • Reviewing the worker role code

Reviewing the worker role code

Action / Script / Screenshot
  1. Start Visual Studio 2010 or Visual Web Developer 2010
  2. Select File -> Open Project
  3. Select GuestBook.sln
/
  • Let’sOpen an existing Windows Azure project.
  • In the following demos we are going to use the Guestbook application.
  • The Guestbook application is a simple application that exercises many features of the Windows Azure platform.
/
  1. Once the solution is open, point out the projects:
  2. GuestBook is the cloud project. This is what defines the structure of the cloud solution, which roles are present and any service configuration.
  3. GuestBoos_WorkerRole is the worker role, written in VB.
/
  • As you can see we have several projects
  • Most of the projects are simply either standard class libraries, or asp.net web sites.
  • The important project for us is GuestBook
  • This defines the structure of our service.
  • You can see it has two roles, GuestBook_WebRole provides the web role, and GuestBook_WorkerRole provides the worker role.
/
  1. Expand the GuestBook_WorkerRole
/
  • Now lets take a look in more detail at the worker role.
  • The first thing to notice is that the GuestBook_WorkerRoleis actually written in VB. Windows Azure can execute any .NETFramework code, including VB.Net.
  • The next thing to notice is that the project is in fact a class library.
/
  1. Open the WorkerRole.vb file
  2. Point out the imports statement
  3. Point out the class inherits from RoleEntryPoint
/
  • There is only 1 class in the project, which represents the worker role.
  • First we have some imports to the referenced Microsoft.WindowsAzure.ServiceRuntime.
  • This namespace contains the API for Windows Azure, including the RoleEntryPoint, which this class inherits from.
  • RoleEntryPoint provides several methods which are called by the fabric to start, stop and get the health status of the worker.
/
  1. Navigate to the Run method.
/
  • The Run method is the method that is called by the fabric once the worker is deployed and ready to run.
  • The run method is where you should perform your worker tasks.
  • You should not return from the Run method. This is seen as an error by the fabric, and your worker role can be restarted.
/
  1. Show the while true loop
/
  • In this sample, the start method contains a while true loop never exits.
  • The actual work carried out by the queue is irrelevant in this demo, we’ll take a look at it in a later demo.
/
  1. Navigate to the OnStart method.
/
  • Override the OnStart method to run initialization code for your role.
  • If the OnStart method returns false, the instance is immediately stopped. If the method returns true, then Windows Azure starts the role by calling the Run method.
  • A web role can include initialization code in the ASP.NET Application_Start method instead of the OnStart method. Application_Startis called after the OnStart method.
  • Any exception that occurs within the OnStart method is an unhandled exception.
/
  1. Type Public Overrides, then press space, then choose OnStop()
/
  • There is 1 more method we may wish to implement depending upon our design.
  • This is the OnStop method.
  • OnStopis called whenever the fabric is going to shutdown your worker role – for whatever reason. It’s up to you to respond within a timely fashion, otherwise your worker role will simply be “killed”.
  • You have around 20 seconds to respond to a stop method.
  • OnStopis not called when an actual hardware or other catastrophic failure occurs. For this reason, you may choose not to implement stop, and instead write your worker to handle failures.
  • As a reminder, when writing worker roles you can use any supported .NET language.
/

Summary

In this demo, you saw how a worker role is constructed, which interaction points there are and how to respond to start/stop calls.