简体   繁体   English

编辑队列中的MSMQ消息

[英]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. 我知道这是可能的,因为应用程序“ QueueExplorer ”就是这样做的。

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? 有谁知道我如何加载MSMQ消息(这不是队列中的第一个),编辑它,并将其保存回队列?

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. MSMQ消息应该是不可变的。 The best you can do is read the message and send an edited copy of the message back to the queue. 您可以做的最好的事情是阅读消息并将编辑后的消息副本发送回队列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM