Helper class that simplifies MSMQ access code.
For a list of all members of this type, see MessageQueueTemplate Members .
Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.
Using the System.Messaging.MessageQueue class directly in application code has a number of shortcomings, namely that most operations are not thread safe (in particular Send) and IMessageFormatter classes are not thread safe either.
The MessageQueueTemplate class overcomes these limitations letting you use a single instance of MessageQueueTemplate across multiple threads to perform standard MessageQueue opertations. Classes that are not thread safe are obtained and cached in thread local storage via an implementation of the IMessageQueueFactory interface, specifically DefaultMessageQueueFactory.
You can access the thread local instance of the MessageQueue associated with this template via the Property DefaultMessageQueue.
The template's Send methods will select an appropriate transaction delivery settings so calling code does not need to explicitly manage this responsibility themselves and thus allowing for greater portability of code across different, but common, transactional usage scenarios.
A transactional send (either local or DTC transaction) will be attempted for a transacitonal queue, falling back to a single-transaction send to a transactional queue if there is not ambient Spring managed transaction.
The overloaded ConvertAndSend and ReceiveAndConvert methods inherit the transactional semantics of the previously described Send method but more importantly, they help to ensure that thread safe access to IMessageFormatter instances are used as well as providing additional central location to put programmic logic that translates between the MSMQ Message object and the your business objects. This for example is useful if you need to perform additional translation operations after calling a IMessageFormatter instance or want to directly extract and process the Message body contents.
Assembly: Spring.Messaging (in Spring.Messaging.dll)