Let say I have two instances of the same app interacting with a backend service in Service Broker. How can each instance know to handle only conversations it initiated and ignore the rest? If I recall correctly, every RECEIVE will remove the message from the queue.
Here's an example:
-- Assume the SquareService return the square of the number sent to it
-- Instance 1
BEGIN DIALOG @Conversation1
FROM SERVICE InitService
TO SERVICE 'SquareService'
ON CONTRACT (MyContract)
WITH ENCRYPTION = OFF;
SEND ON CONVERSATION @Conversation1 MESSAGE TYPE MyMessageType('1');
-- Instance 2
BEGIN DIALOG @Conversation2
...;
SEND ON CONVERSATION @Conversation2 MESSAGE TYPE MyMessageType('2');
Now who should I write the RECEIVE
statement so that Instance 1 will correctly get 1 and Instance 2 get 4 back?
You are already using a Conversation Group. Is this not sufficient for your needs when Receiving the messages? -> using GET CONVERSATION GROUP and RECEIVE together you can read more about it here: http://technet.microsoft.com/en-us/library/ms166131%28v=sql.105%29.aspx and also here Sql Server Service Broker Conversation Groups