SQL Service Broker Peek on queue
I'm writing a C# application that uses SSB queues to communicate with other systems. When receiving a message from a SSB queue, I am not always sure I am able to handle it. Therefore I would like to peek at the queue (or maybe just being notified that there is a message, not neccessarily it's content), but at the same time using the SSB syntax, including WAITFOR.
The reason to do this is that I want to be 100% sure that no message ever get lost, even if the receiver experiences some kind of irrecoverable failure. Another solution might be to wrap it up in a transaction, but this would require much more code changes than just a peek call. If anyone has any alternative sol开发者_Go百科ution to ensure that no data get lost, I am all ears.
You should first receive the message and then decide whether or not you can handle it. If you can't, "write a log message and bail out" - but commit the receive transaction. If you rollback the transaction (or just do peek on the queue as you intended to) you will end up in a situation where there's a message you cannot handle in the queue and you keep peeking (or receiving/rolling back) it indefinitely.
精彩评论