Completing a Conversation in a Single Database

This tutorial is intended for users who are new to Service Broker, but are familiar with database concepts and Transact-SQL statements. It will help new users get started by showing them how to build and run a simple conversation in a single database.

What You Will Learn

This tutorial shows you how to create the database objects that are required to support a simple request-reply Service Broker conversation. You will then start a conversation and use it to transmit messages.

Each Service Broker conversation has two ends: the conversation initiator and target. You will perform the following tasks:

  • Create a service and queue for the target and a service and queue for the initiator.

  • Create a request message type and a reply message type.

  • Create a contract that specifies request messages go from the initiator to the target, and that reply messages go from the target to the initiator.

You will then perform a simple conversation:

  • Start the conversation.

  • Send a request from the initiator to the target.

  • Receive the request at the target and send a reply to the initiator.

  • Receive the reply at the initiator.

  • End the conversation.

Messages are not transmitted across a network for conversations that have both ends in the same instance of the Database Engine. Database Engine security and permissions restricts access to authorized principles. Network encryption is not needed for this scenario.

This tutorial is divided into three lessons:

Requirements

To complete this tutorial, you should be familiar with the Transact-SQL language and how to use the Database Engine Query Editor in SQL Server Management Studio. You must be a member of the db_ddladmin or db_owner fixed database roles for the AdventureWorks2008R2 sample database, or the sysadmin fixed server role.

Your system must have the following installed: