Back To Basics: Service Broker Contracts - SQL Server with Mr. Denny

SQL Server with Mr. Denny

Jun 2 2008   11:00AM GMT

Back To Basics: Service Broker Contracts



Posted by: mrdenny
SQL, Service Broker, Back To Basics, Contract, Queue

Every Service Broker conversation requires a contract.  The contract defines which message type or types will be used, as well as who (sender or receiver) can use which message types.  The contract is specified when the conversation is created.

The syntax for creating the contract is pretty straight forward.

CREATE CONTRACT [ContractName]
(MessageType SENT BY ANY)

The SEND BY portion can be used as many times as is needed for each Message Type which is defined on the contract.  It must be listed at least once as you can not have a contract with no message types.  You can specify that the Message Type be used by the INITIATOR, the TARGET or by both (by using the ANY keyword).

A more complex Contract would look something like this.

CREATE CONTRACT [ContractName]
(MessageType_I SENT BY INITIATOR,
MessageType_T SENT BY TARGET)

Denny

Comment on this Post


You must be logged-in to post a comment. Log-in/Register

Improving SQL Service Broker Performance - SQL Server with Mr. Denny  |   Nov 3 2008   11:02AM GMT

[...] Message Type is called MT_ObjectDelete My Contract is called CT_ObjectDelete My Queues are called Q_ObjectDelete_Source and Q_ObjectDelete_Destination [...]