让 Service Broker 在检测有毒消息方面不那么激进?

发布于 2024-08-03 12:04:41 字数 688 浏览 8 评论 0原文

Sql Service Broker 使用以下启发式方法来确定队列中何时存在阻止应用程序执行任何有用工作的消息:

“Service Broker 提供自动有害消息检测。当包含 RECEIVE 语句的事务回滚五次时,Service代理通过自动将队列状态设置为“关闭”来禁用事务从中接收消息的所有队列。” (http://msdn.microsoft.com/en-us/library/ms166137。 aspx

我对这种基本方法很满意,但是有什么办法可以将重试次数从五次更改为更高的次数,也许是二十次?

这对我有用的原因是,我当前用来处理队列的代码是 Sql Server 外部的一个应用程序,它有大约 10 个工作线程,每个线程都有一个独立的 SqlConnection,并且每个线程都执行自己独立的RECEIVE 语句。如果该应用程序由于某种原因终止,这可能会导致每个工作线程单独的回滚事务,这足以禁用队列。相反,我希望能够在不禁用队列的情况下终止我的应用程序。我可能应该重写应用程序以使用单个 SqlConnection,但如果我可以简单地说类似

ALTER QUEUE MyQueue SET RollbacksBeforePoison=20

这样的事情可能吗?

Sql Service Broker uses the following heuristic to determine when you have messages in your queue that are preventing your application from doing any useful work:

"Service Broker provides automatic poison message detection. When a transaction that contains a RECEIVE statement rolls back five times, Service Broker disables all queues that the transaction received messages from, by automatically setting the queue status to OFF." (http://msdn.microsoft.com/en-us/library/ms166137.aspx)

I'm fine with this basic approach, but is there any way to change the # of retries from five to something higher, maybe twenty?

The reason this would be useful to me is that the code I'm currently using to process the queue is an app outside of Sql Server that has around 10 worker threads, each of which has an independent SqlConnection and each of which executes its own independent RECEIVE statements. If this application dies for some reason, this potentially causes a separate rollback transaction for each worker thread, which is enough rollbacks to disable the queue. In contrast, I would like to be able to kill my application without disabling the queue. I should probably rewrite the application to use a single SqlConnection, but it would be a lot easier if I could just say something like

ALTER QUEUE MyQueue SET RollbacksBeforePoison=20

Is anything like that possible?

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

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

发布评论

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

评论(2

ま昔日黯然 2024-08-10 12:04:41

不可以,有害消息检测回滚计数被硬编码为 5,并且您无法更改它。但是,当队列被禁用时,队列上会针对 引发事件通知BROKER_QUEUE_DISABLED 事件。您可以订阅此事件并拥有一个处理程序来通知管理员,甚至重新启用队列。此外,应用程序可能会利用类似 外部激活机制可以根据传入消息的速率调整其线程池大小。

已更新

从 SQL Server 2008 R2 开始,有一个新选项 更改/创建队列

POISON_MESSAGE_HANDLING(STATUS = OFF/ON)

指定是否有毒消息
处理已启用。默认为
开。

有有害消息的队列
处理设置为 OFF 将不会
连续五次后禁用
事务回滚。这允许
自定义毒消息处理系统
由应用程序定义。

No, the poison message detection rollback count is hard coded to 5 and you cannot change it. But when a queue is disabled an event notification is raised on the queue for the BROKER_QUEUE_DISABLED event. You can subscribe to this event and have a handler that either notifies an administrator, or even re-enables the queue back. Also the application could probably leverage something like the external activation mechanism to tune its thread pool size to the rate of incoming messages.

Updated

As of SQL Server 2008 R2 there is a new option for ALTER/CREATE QUEUE:

POISON_MESSAGE_HANDLING(STATUS = OFF/ON)

Specifies whether poison message
handling is enabled. The default is
ON.

A queue that has poison message
handling set to OFF will not be
disabled after five consecutive
transaction rollbacks. This allows for
a custom poison message handing system
to be defined by the application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文