If you have read something about Azure’s queue you have probably seen some picture like this:
A producer is anything (a class) that, in some moment, enqueue a message; more exactly this “anything” is something that take the role of message producer. For example it can be a MVC controller, more usually it can be an application-service or a domain-event but it can be even a view.
To simplify the work with messages, to our team, I have created two very simple classes on top of Microsoft.WindowsAzure.StorageClient. The main target of these two classes is establish some conventions and make the message strongly typed (it represent a limitation of the capability of Azure’s queues but for our works it is ok).
Giving a message like this:
I would enqueue a new message with a line like this:
When you want work with a message you will probably need some more information than the pure message data so a message in a queue is represented by:
The base convention is about the name of the queue which is the name of the class representing the message. For the example above the name of the queue is: newsviewed. The second convention is about the format of the message-content: ours Azure-queues will contains just strings, more exactly the JSON serialization of the class representing the message.
The MessageQueue implementation
Currently the max message size is 8KB, perhaps, hopefully NO, we will need more space so the MessageQueue<TMessage> class have to be extensible to allow a gzip/de-gzip of the content or it needs take the real content from a blob… so far it is far away of our needs and I hope we will never need it.
The implementation is:
as you can see it is basically a wrapper.
The AzureAccount class, present in the parameters-less constructor, is our static class to access all our storages accounts.
The JsonConverter is the class of the famous Newtonsoft.Json.
The more simple step is done, the next will be about the three parts of the consumer.