Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

Execute long-running updates using Service Broker activation Expand / Collapse
Posted Tuesday, August 13, 2013 9:02 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Sunday, April 10, 2016 3:13 PM
Points: 364, Visits: 394

A typical Service Broker activation procedure is structured something like this:

begin transaction
waitfor receive
do something
end conversation
commit transaction

In my case the "do something" is a batched, very long-running stored procedure which will hold locks etc. The process is designed to be resumeable and I do not want the entire thing to be run inside a single explicit transaction.

What ways are there to cope with this situation - to run the payload proc outside the scope of the activation proc transaction without violating the integrity of the "receive + end conversation" unit of work?

Thanks :)
Post #1484057
Posted Wednesday, August 21, 2013 1:07 PM

UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Wednesday, October 19, 2016 12:41 PM
Points: 1,447, Visits: 3,254
What I have done in the past is to have the broker request procedure write a request row to a separate table then send the ID of the row into the broker queue message. Long running or multi-stage transactions can be broken down into steps, having whatever process (or processes) performing the operations updating a status in that row after completion of each phase. That way you can close out the transaction from the activation procedure and keep it short which is what you need to do.

If you can't (or don't want) to do your long running process that way you might consider turning off activation and just executing the activation procedure from and external process (multi-threaded or otherwise).

The probability of survival is inversely proportional to the angle of arrival.
Post #1486879
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse