Home Forums Programming Service Broker Asynchronous SP execution via Service Broker RE: Asynchronous SP execution via Service Broker

  • Hi

    There are some issues and things you need to consider with this approach:

    Since Service Broker honors transactions, the first acknowledge message will not be delivered until the transaction is committed, and since you run SomeLongRunningSP inside the same transaction as the RECEIVE statement the message will no be delivered until the sproc has completed.

    I would just trust SQL Server with delivery once the initiator message has been sent (and by that I don't mean delivered at the target) and the transaction has committed. Make sure you monitor sys.transmission_queue for delivery failures. You should also set up monitoring of the status of the queues in case they are disabled (due to poison message detection). It happend a lot for me in the beginning.

    What happens if execution of SomeLongRunningSP fails? You should not rollback the transaction and reread the message becuase this could lead to poison message detection and disabling of the queue. I've usually implemented retry logic by setting up a retry table together with BEGIN CONVERSATION TIMER. Monitor the retry table to detect any failures.

    Database mail uses this kind of logic.

    Do you need to inform the client when the sproc execution is completed?