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); }