views:

61

answers:

2

Can an MSMQ queued messages survive a service/server restart? What I mean is that if a queue has messages and the server were to experience a hard restart, would the messages be still available in the queue after the restart?

+4  A: 

To achieve this you have to mark the messages as Recoverable. By default, MSMQ messages are only held in memory, but Recoverable messages are backed to disk to enable reliable MSMQ Messaging.

using System.Messaging;

Message recoverableMessage = new Message();
recoverableMessage.Body = "Sample Recoverable Message";
recoverableMessage.Recoverable = true;
MessageQueue msgQ = new MessageQueue(@".\$private\Orders");
msgQ.Send(recoverableMessage);

There is an overview of this area at Reliable Messaging with MSMQ and .NET.

Transactional messages do not need to be manually marked as recoverable - this is implicit in the fact they are part of an MSMQ-based transaction.

Steve Townsend
A: 
John Breakwell