Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Service Broker Be Less Aggressive About Detecting Poison Messages?

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?

like image 784
Chris Avatar asked Sep 02 '09 00:09

Chris


People also ask

What is poison message handling?

A poison message is a message that has exceeded the maximum number of delivery attempts to the application. This situation can arise when a queue-based application cannot process a message because of errors. To meet reliability demands, a queued application receives messages under a transaction.

Which component of Azure provides poison message handling?

Service broker provides automatic poison message detection, which disables the service queue upon five consecutive transaction rollbacks in trying to receive messages from the queue.


1 Answers

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.

like image 151
Remus Rusanu Avatar answered Oct 05 '22 07:10

Remus Rusanu