Search code examples
sql-servert-sqlsql-server-2012service-broker

Service Broker message flow


I have two different servers in two locations. I need to use asynchronous exchange of data.

  • Server A is our data server, we store customer info here.
  • Server B is our proccesing server, we process production.

Each production operation on server B has a production group. What I need to do is:

  1. A to send a message to B with a question: What operations are planned for today in this group(GUID).
  2. B has to answer with an XML list of operations scheduled for today.
  3. A has to answer with an XML list of operations to cancel
  4. B has to cancel operations and end conversation

My question is: What is the right way to go about this? Can I do this in just a single dialog using one contract? Should I?

With a contract like this:

CREATE CONTRACT [GetScheduledContract] 
AUTHORIZATION [xxx]
(GetScheduledOutCalls SENT BY INITIATOR,
ReturnScheduledOutCalls SENT BY TARGET,
DeleteScheduledOutCalls SENT BY INITIATOR)

Or should I separate the tasks to different contracts and dialogs?


Solution

  • What you have seems good to me as an MVP (i.e. if things go right, it'll work). A couple of things:

    1. Consider adding one more reply from the target saying "operation completed successfully" before closing the conversation. Upon receipt, the initiator can also close their end of it.
    2. What happens if any of those operations is explicitly not able to be completed (e.g. in your step 4, the request is to delete something that's not present or that delete causes a foreign key violation)? I'd add in some sort of error message type (sent by any) that allows either side to tell the other "hey… something went wrong".
    3. What happens if any of those operations is implicitly not able to be completed (e.g. the message never gets delivered)? The other side may not respond for some reason. Build in some way to at least detect and alert on that.