I need to be able to edit messages in my error queue (so that they can be resent to the actual queue for reprocessing).
I would like to make my own custom tool to do this (because my messages require specific formatting to make them easily readable by support personnel).
I know that this is possible because the application "QueueExplorer" does this.
Does anyone know how I can load an MSMQ message (that is not the first one in the queue), edit it, and save it back to the queue?
Navigate to 'Computer Management (Local) > Services and Applications > Message Queueing > Private Queues' to see the two private queues used by my application.
Microsoft Message Queuing, better known by its nickname MSMQ, passed away peacefully in its hometown of Redmond, Washington on October 14, 2019, at the age of 22. It was born in May 1997 and through 6.3 versions lived a very full life, bringing the promise of reliable messaging patterns to users all around the globe.
Purpose. Message Queuing (MSMQ) technology enables applications running at different times to communicate across heterogeneous networks and systems that may be temporarily offline. Applications send messages to queues and read messages from queues.
In the Content view, right-click the queue, then click Clear Messages... The Clear Queue dialog opens. Select the method to use to clear the messages from the queue: If you use the CLEAR command, all of the messages are cleared from the queue.
Iterate through the messages, using something like this:
List<Message> msgList = new List<Message>();
using (MessageEnumerator me = queue.GetMessageEnumerator2())
{
while (me.MoveNext(new TimeSpan(0, 0, 0)))
{
Message message = me.Current;
msgList.Add(message)
}
}
You can then iterate through the list, processing each message. Create a new message, based on the original. Then remove the existing message, and add the new one.
foreach (Message message in msgList)
{
//Create a new message as required, add it, then remove the old message
MessageQueue.ReceiveById(message.MessageId);
}
MSMQ messages are supposed to be immutable. The best you can do is read the message and send an edited copy of the message back to the queue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With