2
votes

I'm wondering if its possible to write a Powershell script to move a message from one MSMQ queue to another?

I have a few failed messages (i.e. messages that did not complete because they involved, say, a call to a server that was down, for example) in an error queue that I would like to retry by moving them back into their original processing queue. I am using NServiceBus v6 handlers to listen for messages that enter the original processing queue that will resend the message if they are put back into that queue.

Has anyone done this before using Powershell?

In particular, I would like to do the following in Powershell:

  1. Find a message based on a specific identifier (string) within the message body
  2. Move this message to a specific queue

I know Powershell has commands such as Move-MsmqMessage. I have been unable to find an example online that I can re-use for this function.

Any help much appreciated.

1
Move-MsmqMesage only works on subqueues which are essentially just partitions within the same queue. It doesn't move messages between queues.John Breakwell

1 Answers

2
votes

If you have messages in the error queue from NServiceBus, you can use this tool to return them to the original queue they were in.

https://github.com/ParticularLabs/MsmqReturnToSourceQueue

It checks the headers what the original queue was and sends them there again. The idea is that any endpoint can send messages to the same error queue. They can then either be digested by ServiceControl or any other tool. If you leave them in the error queue, this ReturnToSourceQueue can send them back to the original queue.