In my new project (UXRisk) we had a requirement to do a lot of background processing, based on messages passed over Azure Service Bus. We did a lot of research online and found good examples of how to properly to this and the outcome was a project we call AzureWorkers.
AzureWorkers makes it super easy to run multiple workers in one Azure Worker Role, all async and safe. You as the implementor basically have to just inherit from one out of three base classes (depening on Service Bus/Storage Queue is used or not) and that class will run in its own thread and will be restarted if it fails.
There are four supported scenarios:
- Startup Task – Will only be executed when the Worker Role starts. Implement IStartupTask to enable this scenario.
- Base Worker – Will be called continuously (basically every second), for you to do work and control the timer. Inherit from BaseWorker to enable this scenario.
- Base Queue Worker – Will call the Do method with messages retrieved from the Azure Storage Queue. Inherit from BaseQueueWorker to enable this scenario.
- Base ServiceBus Worker – Will call the Do method whenever a message is posted to the topic specified in the TopicName overload. Inherit from BaseServiceBusWorker to enable this scenario.
On GitHub an example project is included to document these three scenarios. To get started using AzureWorker you can get the nuget package.
AzureWorker depends on these projects:
- Ninject – version 3.0.2-unstable-9038
- Ninject.Extensions.Azure – version 3.0.2-unstable-9009
- Ninject.Extensions.Conventions – version 3.0.2-unstable-9010
- Microsoft.WindowsAzure.ConfigurationManager – version 188.8.131.52
- WindowsAzure.ServiceBus – version 184.108.40.206
There are a at least two issues with the code right now:
- If the processing of a message fails it will re-post the message directly and retry, no waiting time (Service Bus Worker).
- The implementer has to delete messages manually (by intent).
- It is depending on Ninject, not a generic IoC framework
We will accept PRs to alleviate these issues.