Introduction of Service Broker in SQL Server
Before I actually start making you understand about what Service Broker is, I have explained some practical scenario where I have introduced Service Broker recently. If you would like to know those scenarios, have a look at my earlier article “Importance of Service Broker”.
Service Broker is an asynchronous message processing framework build directly into the SQL Server. Following are four important objects of Service Broker.
1.) Message Types
4.) Service Program
Message Types: Message Types is the first and one of the important objects of SQL Server Service Broker. Message Type do the important job of validating message before sending it to queue. There are four type of message types available.
- XML Validation against XML Schema
- Well Formed XML
- No Validation (no validation at all, especially for binary data)
- Empty (there is no message body required)
Contracts: Contracts decides which message type suppose to be used by Service Broker for a particular task. In service broker we used to send message to the other service to process the message and Contract decides message type suppose to be used between two services. If you send the message type from one service to another service which is not defined in contract, message will be rejected. You can easily find the message types being used from the sender to receiver by looking at Contract definition.
Queue: Queue is a native SQL Server database object and very important part of SQL Server service broker. Queue stores message (not matter whether it is from target service or initiator service). When Service Broker receives a message, It first gets validated by Message Types and after successful validation check, message used get stored in queue for further process. Queue is like a SQL Server table where you can even query to see the message but can’t execute DML statements explicitly to manipulate data for queue table manually. Since queue is basically a table of SQL Server, it comes with SQL Server database backup and restore.
Service Program: Service Program used to process message from the queue. When a new message arrives, Service Broker automatically calls service program defined. If internal activation is used, SQL Server Stored Procedure can be the service program whereas, when external activation is used, you can have your own separate application for service broker’s service program.
Well, these are some basic objects with brief introduction of Service Broker. I will come up with more information and practical stuff related to Service Broker soon.
Till than Stay tuned and enjoy SQL!!!!!
Reference: Ritesh Shah
Note: Microsoft Books online is a default reference of all articles.