You do not need SQL notifications or SQLDependency. Each instance can perform:
WAITFOR(
RECEIVE TOP(1) * FROM {NameOfQueue}
), TIMEOUT @timeoutvalue;
This command will WAIT, leaving the connection open until a message appears or a timeout occurs. You will not receive a message in the timeout, so just connect and try again.
Each message can be received by only one process. Internally, the row in the Server Broker queue is locked, and other readers will WRITE the locked rows.
Since SQL can be a little more complicated, I wrote what I find useful a wrapper class that you can use .
source
share