0

Good day,

I would like to ask a conceptual question that has been tearing my mind for a while. There is no right or wrong answer here, probably, but I hope to get better understanding of my options.

Situation: I have a Windows Azure Application. It consists of ONE Web Role with ONE instance and ONE worker role with TWO instances.

The main focus is on the worker role. It implements Quartz.NET scheduler to perform a task of getting information from a CRM system, making a table out of it and uploading to FTP server, say, every 8 hours. Very simple, nothing fancy.

The web role is used for manually triggering the job if someone needs it to run between 8 hour intervals. Simple user interface with pretty much one button.

However I would like to have a possibility to make it possible to change some configuration options of the worker role from the web role. For example credentials of destination FTP server and schedule of the job e.g. make it run hourly instead of 8 hours. The configuration DOES NOT need to persist if role goes offline. At the moment config is one in a static class.

This wouldn't seem a problem if I was running one worker role instance: I would send a message from web role via queue and change some static variables in the worker role, for example. But what confuses me is the message queues can be only picked up by one role instance, not both at the same time. So I will end up having the job run every 8 hours in one instance and every hour on another.

Is there any way to notify both instances that configuration needs to change?

David Makogon
  • 64,809
  • 21
  • 130
  • 175
Andrey Zh.
  • 47
  • 6

2 Answers2

1

There are several ways you could accomplish this. Let me offer two, aside from what @Gaurav suggested:

  1. Windows Azure configuration settings. If you store your ftp server name and time interval as configuration settings, and then change the configuration, each role instance can capture and handle the RoleEnvironment.Changing event, and take action based on new settings.
  2. Service bus pub/sub. You can have each role instance subscribe to a configuration change topic. Then, whenever you have a change, publish the change to the topic, and each instance, being subscribers, will receive the message and act accordingly.
David Makogon
  • 64,809
  • 21
  • 130
  • 175
  • Thank you! Regarding option one: would the approach be a loop that periodically checks 'RoleEnvironment.Changing' event? I would prefer not to use service bus, because, if I understand correctly, it comes at additional cost and I would prefer to keep them at minimum. – Andrey Zh. Aug 04 '12 at 09:17
  • You just have to set an event handler and wait for it to be called. No looping. You'll just need to carefully code how you handle it (or simply let your role instance get restarted). More info [here](http://msdn.microsoft.com/en-us/library/windowsazure/gg432963.aspx) and [here](http://technet.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleenvironment.changing). – David Makogon Aug 04 '12 at 13:26
  • Makes very good sense. This is then what I will do. Thank you again. – Andrey Zh. Aug 05 '12 at 19:52
0

One possibility would be to do a "PEEK" at message by your worker role instances instead of "GET" message. That way the message will remain visible to all the instances. Obviously the challenge there would be when to delete the message. Other alternative would be create a separate queue for each worker role instance (you can name the queues so that each worker role instance would actually GET the message from the queue intended for that instance e.g. if your worker role instances are say WorkerRole1_IN_0, WorkerRole1_IN_1, you could name your queues like workerrole1-in-0, worker-in-1 and so on). Just thinking out loud :)

Gaurav Mantri
  • 100,555
  • 11
  • 158
  • 192
  • That makes sense as well, I was thinking about this as a possibility. The only issue that this is not a very elegant solution so to say, at it requires changes in the code for every instance added. Though, it's very unlikely that I will be using more then two. – Andrey Zh. Aug 04 '12 at 09:21