Offline Application Block: persistent MSMQQueueStorageProvider

Microsoft Smart Client Offline Application Block makes possible to build applications that are network aware and that are able to work online or offline. When offline you can enqueue messages for central services using many different kind of QueueStorageProvider. One of the pre-built QueueStorageProvider is MSMQQueueStorageProvider that, as you can argue from its name, is a queue provider based on MSMQ. It works with a private queue not transactional by default. Sometimes it happens that you would like to make your messages persistent in order to keep trace of them in case of your Smart Client host shutdown, reboot, crash, etc.

In order to have a MSMQ Queue that keeps track of messages even if you switch off your client you need to mark your messages as Recoverable. To do that you can do either of:

  • Set to true the property Recoverable of a System.Messaging.Message instance before enqueueing it
  • Mark the queue as transactional

By default MSMQQueueStorageProvider, doesn't use a transactional queue and doesn't mark a message as Recoverable.
Here is a code snippet to replace in MSMQQueueStorageProvider in order to have Recoverable messages:


/// /// Responsible for storing array of bytes into MSMQ /// /// Object as a byte array to store into MSMQ override protected void DoEnqueue(byte[] objectToStream) { Message msg = new Message(objectToStream); msg.Formatter = queue.Formatter; msg.Recoverable = true; queue.Send(msg); }

2 Comments

  • Have you ever considered about adding a little bit more than just your articles? I mean, what you say is important and everything. However think about if you added some great images or video clips to give your posts more, "pop"! Your content is excellent but with images and videos, this blog could certainly be one of the greatest in its niche. Very good blog!

  • While the on-going set all the way up is impressive - that shelf associated with items with Apple past is actually interesting. I want to take some sort of closer have a look at some of your memorabilia!

Comments have been disabled for this content.