NServiceBus:如何从错误队列中移动消息

发布于 2024-10-07 13:31:33 字数 80 浏览 0 评论 0原文

我的应用程序中有一个错误,导致许多消息被移动到错误队列中。现在我已经修复了该错误,是否有一种简单的方法可以将它们移回原始队列以便可以对其进行处理?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨落星ぅ辰 2024-10-14 13:31:33

您可以使用简单的命令行工具 ReturnToSourceQueue.exe,它包含在 NServiceBus 中。

它位于 tools 文件夹 IIRC 中。

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

It's located in the tools folder IIRC.

冷月断魂刀 2024-10-14 13:31:33
  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();
            }
  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();
            }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文