Edit MSMQ messages in a queue
Asked Answered
H

2

6

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?

Hydrated answered 9/3, 2012 at 16:53 Comment(5)
As a side note: I would normally just buy QueueExplorer, but it does not allow my messages to be formatted in a way that is useable to my users. I also need to integrate the feature of returning the message back to the original queue. And lastly QueueExplorer is insanely slow for very simple tasks.Hydrated
This probably won't be very popular, but if QueueExplorer is written in .NET (which it appears it is) why not just run it through a decompiler to see how they do it?Cultivated
@Hydrated QueueExplorer says When you load, copy, drag&drop or edit message it will go to the end of queue. (see cogin.com/mq/qelimitations.php) so basically they load the message, and after editing they delete original and enqueue the edited messages. They don't do "in-place-editing" if that is what you are after...Roark
@Roark - that is what I wanted... looks as if it may not be possible :(Hydrated
@Hydrated You could just write a tool that dequeues the message from error queue, "processes" it by presenting it to a user who edits it and then enqueues it into the "actual processing queue"... wouldn't need "in-place-editing" and wouldn't need to access messages that are not the first one... won't that do what you need ?Roark
D
3

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);
}
Delacruz answered 9/3, 2012 at 17:11 Comment(0)
M
3

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.

Mission answered 10/3, 2012 at 23:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.