sql-serverservice-broker

Can you read from Service Broker Queues without removing the message?


We have a situation where when records are updated we want to queue a message to be read by application that will then read the message and do something with it (routing it on the ESB somewhere).

The issue that was brought up was "What if we read the message from the queue and then the application fails before the message is forwarded on etc?" Is there a way to get the message, act on it, and then once sure its been processed, remove it from the queue?

Is there a better way to account for this? The solution they have created so far involves removing SB altogether and writing triggers to put data into a table which would then be polled, processed, and removed.


Solution

  • Typically, one would read (RECEIVE) the message in a transaction and COMMIT on the happy path or ROLLBACK after an error. This will ensure the message is not removed from the queue prematurely. Also, you'll need to consider how to handle poison messages.