Service Broker is a new technology in SQL Server 2005 and provides a solution to message delivery issues that occur while transferring transactional data from one server to another. This technology provides a message-based communication platform and is part of the Database Engine. Database developers develop secure, reliable, and scalable applications with the help of Service Broker. Service Broker is used for the applications that use a single instance of SQL Server 2005 as well as for those that use multiple instances of SQL Server 2005 across the network. It provides reliable messaging between multiple instances of SQL Server 2005. It uses TCP/IP protocol to exchange messages between instances of SQL Server 2005, prevents unauthorized users from accessing the network, and encrypts messages that are sent over the network. It provides a robust asynchronous programming model. Asynchronous programming is the most popular technique in database application programming. In asynchronous programming, the Database Engine handles commands while the application continues to run. Asynchronous programming minimizes response time and enhances application throughput of database applications.
Service Broker consists of various components that make up the entire architecture. It can be divided into three broad components. They are as follows:
- Conversation components
- Service definition objects
- Remoting and security components
All the applications using Service Broker communicate through conversations that involve messages, dialog conversations, and conversation groups.
Service definition objects are database objects that specify the basic design of an application that uses Service Broker. These database objects are message types, contracts, queues, and services. A Service Broker application uses these objects to hold conversation.
Service Broker enables secure and reliable communication between multiple instances of SQL Server 2005, allows you to manage routing, and establishes security for the conversation.
After taking a brief look at the Service Broker architecture, you will learn how to design this architecture. To design this architecture, you will take the following steps:
- Create message types that will be sent by the initiator and returned by the target.
- Create queues where messages will be submitted.
- Create a contract that will establish an agreement between services.
- Create services that will reference the contract.
Now you can start creating a message type. The message type is created using the CREATE MESSAGE TYPE statement.
The syntax for creating a message type is as follows:
CREATE MESSAGE TYPE message_type_name
[ AUTHORIZATION owner_name ]
[ VALIDATION = { NONE
| EMPTY
| WELL_FORMED_XML
| VALID_XML WITH SCHEMA COLLECTION schema_collection_name
} ]
[ ; ]
Here is an example. In this example, you create the message types in the typed XML format for the initiator and the target.
CREATE MESSAGE TYPE CricketRequest
AUTHORIZATION dbo
VALIDATION = WELL_FORMED_XML
CREATE MESSAGE TYPE CricketStatus
AUTHORIZATION dbo
VALIDATION = WELL_FORMED_XML
After creating the message types, you will create the queue where the message types will be submitted. The queue is created using the CREATE QUEUE statement.
The syntax for creating a queue is as follows:
CREATE QUEUE <object>
[ WITH
[ STATUS = { ON | OFF } [ , ] ]
[ RETENTION = { ON | OFF } [ , ] ]
[ ACTIVATION (
[ STATUS = { ON | OFF } , ]
PROCEDURE_NAME = <procedure> ,
MAX_QUEUE_READERS = max_readers ,
EXECUTE AS { SELF | ‘user_name’ | OWNER }
) ]
]
[ ON { filegroup | [ DEFAULT ] } ]
[ ; ]
<object> ::=
{
[ database_name. [ schema_name ] . | schema_name. ]
queue_name
}
<procedure> ::=
{
[ database_name. [ schema_name ] . | schema_name. ]
stored_procedure_name
}
In the example given below, you create the sender queue and the receiver queue to send and receive messages with no parameters.
CREATE QUEUE CricketSender
CREATE QUEUE CricketReceiver
After creating the queues, you will create the contract that will establish an agreement between services.
The contract is created using the CREATE CONTRACT statement.
The syntax for creating a contract is as follows:
CREATE CONTRACT contract_name
[ AUTHORIZATION owner_name ]
( { message_type_name SENT BY { INITIATOR | TARGET | ANY } | [ DEFAULT ] }
[ ,...n] )
[ ; ]
In the following example, you submit a cricket request from the initiator using the CricketRequest message and receive a cricket status from the target through the CricketStatus message.
CREATE CONTRACT CricketContract
(CricketRequest SENT BY INITIATOR, CricketStatus SENT BY TARGET)
After creating the contract, you will create the service that will reference the contract. The service is created using the CREATE SERVICE statement.
The syntax for creating a service is as follows:
CREATE SERVICE service_name
[ AUTHORIZATION owner_name ]
ON QUEUE [ schema_name. ] queue_name
[ ( contract_name | [DEFAULT] [ ,...n ] ) ]
[ ; ]
In the example given below, you create the services for the sender and the receiver.
CREATE SERVICE CricketSenderService ON QUEUE CricketSender (CricketContract)
CREATE SERVICE CricketReceiverService ON QUEUE CricketReceiver (CricketContract)
- Click here to download mcitp test study guide and practice question.
- Pass Microsoft mcitp-database-developer - MCITP Database Developer
- Best exam simulation Microsoft mcitp-sql-server download free trial.
- Click here to download mcts test study guide and practice question.
- Pass Microsoft mcts-sql-server - MCTS Microsoft SQL Server
- Click here to download mcts-sql-server-2008 test study guide and practice question.
- Download practice question and study guide for 70-431 for exam.
- Get certified in first attempt download 70-433 - MCTS: SQL Server 2008, Database Development simulation.
If you like this article, please leave a comment or subscribe this blog via RSS or via e-mail, Bookmark and share through your network. Click the AddThis button below. Thanks.