NServiceBus: How to move messages from the error queue
Asked Answered
R

2

8

I had a bug in my application that cause a number of messages to be moved into the error queue. Now that I have fixed the bug, is there a simple way to move them back to the original queue so they can be processed?

Ricercare answered 14/12, 2010 at 17:47 Comment(0)
C
12

You can use a simple command line tool, ReturnToSourceQueue.exe, which is included with NServiceBus.

It's located in the tools folder IIRC.

Corbin answered 14/12, 2010 at 18:24 Comment(1)
And if you reflect those assemblies, it's pretty easy to figure out how to make additional tooling surrounding this process so you don't always have to log in to the server and run a command line tool.Infusorian
Z
4
  private const string QUEUE_NAME = "private$\\localqueue";
  private const string ERROR_QUEUE_NAME = "private$\\localerrorqueue";

            if (!MessageQueue.Exists(".\\" + QUEUE_NAME))
                return;

            if (!MessageQueue.Exists(".\\" + ERROR_QUEUE_NAME))
                return;

            var messageQueues = MessageQueue.GetPrivateQueuesByMachine(Environment.MachineName);

            var queue = messageQueues.Single(x => x.QueueName == QUEUE_NAME);
            var errorQueue = messageQueues.Single(x => x.QueueName == ERROR_QUEUE_NAME);

            var noOfErrorMessages = errorQueue.GetAllMessages().Count();

            if (noOfErrorMessages == 0)
                return;

            using (var transaction = new MessageQueueTransaction())
            {
                transaction.Begin();

                for (var i = 0; i < noOfErrorMessages; i++)
                {
                    var message = errorQueue.Receive(transaction);
                    queue.Send(message, transaction);
                }

                transaction.Commit();
            }
Zilber answered 18/12, 2010 at 22:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.