I have an NServiceBus endpoint hosted in an azure worker role using AzureMessageQueue as the transport. I am pretty sure that i will be running the worker role with more than one instance configured in azure. I also have a few messages where order is important.
Here is my question. Is there a way to control the order with this type of setup (azure worker role scaled out)?
Should i be looking at a saga? Techniques like the one described below (using the bus.send(object[] messages) overload) will work in this model, i am guessing, but this is only ideal if there are a few messages due to the size limit on an azure queue.
http://mikaelkoskinen.net/post/NServiceBus-In-order-message-processing.aspx
Bus.Send in batch will help and so will configuring the read batch size from the message queue if messages are small enough, you can definitly control the order of messages this way. Batch send will put multiple message instances in the same physical queue message, while batch read will pull multiple physical messages from the queue in one go and process them in order on the node.
Another option is to synchronize the reads in the message handlers, using leases on blobs. See the code of the nsb timeoutmanager on how to use these for synchronization or have a look at steve marx’s blog post on the topic. http://blog.smarx.com/posts/managing-concurrency-in-windows-azure-with-leases
But please do note that azure messages queues DO NOT GUARANTEE ORDER themselves, it’s a best effort. If you want to guarantee order at the transport level, you need to use Azure Servicebus Queues with message ordering enabled.
Kind regards,
Yves