MSMQ messages ending up in the "Transactional dead-letter messages" System Queue
I've been working with a solution recently that uses MSMQ to, well, pass messages between components running on different machines. It's been implemented using WCF as the abstraction layer, so instead of code like this:
MessageQueue messageQueue = new MessageQueue(@".\Private$\rwtest"); messageQueue.Send("My message");
We've got code that looks a little bit like this:
var endpointAddress = "net.msmq://localhost/private/atestqueue"; var channelFactory = new ChannelFactory( new NetMsmqBinding(NetMsmqSecurityMode.None), new EndpointAddress(endpointAddress));
var channel = channelFactory.CreateChannel(new EndpointAddress(endpointAddress)); channel.SendMessage("Hello, world!");
(This is almost certainly more long-winded than is strictly necessary, but I've extracted it from the actual code to help me shake out a mis-configuration somewhere, which means that the channel factory, channel, etc,.. are all constructed by a DI framework, the endpoint address is constructed from configuration settings, and so on)
The problem I was seeing is that every message that's created by the call to SendMessage ends up in the "Transactiondal dead-letter messages" System Queue:
It turns out (and for whatever reason, this was something I struggled to easily determine the answer to!) the Class of "Nontransactional queue" on each of the messages means that the code is attempting to send messages to a Transactional Queue, however the queue itself has been configured to be Nontransactional. Rather than this resulting in an exception being thrown, the message is accepted but then falls through into the Transactional dead-letter message queue. Here's the mis-configured queue:
It's not possible (or at least doesn't appear to be possible) to change the Transactional/Non-transactional nature of a Message Queue, so the solution was to delete and re-create the queue.