Windows Azure – Compute (Worker Role)
Before we start of with the worker role, we might talk about few things over the course which we have already discussed on our previous part. If you haven’t read the previous part and you aren’t able to follow something, I would recommend reading the previous part.
As I already briefed in part 2, the worker role is basically a worker process which is normally configured to run on an infinite loop. We will create which is something similar to as we spoke.
Create an application
As we have already created a solution, we will make you use of the same.
Now to add a project, in the solution explorer, right click on the “Roles” folder and click “Add -> New Worker Role Project”. We will name it as “CloudTutorialWorker”. Now as we already saw in the previous part, there will be another entry “CloudTutorialWorker” in the “Roles” folder which contain similar settings as in a web role.
We will not talk about the settings and other features about the project as we have already covered the same in the previous project.
Lets discuss code
Before we go ahead and run the application, we will have a look on the what the code is and how does it work.
As in a normal worker or windows service, there are two methods auto populated; “Run” and “OnStart”. You can also override “OnStop” event to do functionalities on stop of the process.
In our code, it is written to show a log info “Working” every 10 seconds. Similarly we can write any process to run endlessly.
Lets go ahead and run the application. Press F5 and it will start the application as we saw in our previous part. So when you run the application, you will find the web page being shown. So how do we find the worker role running. Open the simulation environment and have a look on the “Development Fabric”.
Now as in the picture we have both and the “CloudTutorialWeb” and “CloudTutorialWorker” running and if you select the worker, we could see the information popping up for every 10 seconds as we have programmed.
Now you can apply your own logic and work on the same. We will discuss more on the application while we try writing samples which will make use of the entire Azure technology.
Now we are done with the “Worker Role” and the “Compute” section of the Azure technology. Our agenda for the next part would be on the “Storage” and we will also discuss the various options it offers and will try to code on the same.