Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edit MSMQ messages in a queue

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?

like image 458
Vaccano Avatar asked Mar 09 '12 16:03

Vaccano


People also ask

How can I view MSMQ messages and queues?

Navigate to 'Computer Management (Local) > Services and Applications > Message Queueing > Private Queues' to see the two private queues used by my application.

Is MSMQ dead?

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.

What is Microsoft Message Queue MSMQ server?

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.

How do I clear my message queue?

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.


2 Answers

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);
}
like image 131
Cronan Avatar answered Oct 21 '22 19:10

Cronan


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.

like image 20
John Breakwell Avatar answered Oct 21 '22 19:10

John Breakwell