[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

The Conversation Priority sample provides a simple Service Broker application that shows you how to user broker priorities for sending and receiving a messages using Service Broker.

Samples are provided for educational purposes only. They are not intended to be used in a production environment and have not been tested in a production environment. Microsoft does not provide technical support for these samples. Sample applications and assemblies should not be connected to or used with your production SQL Server database or your report server without the permission of the system administrator.

Before running this sample:

·                      Make sure that SQL Server is installed, including the SQL Server Database Engine component.


·                     
Install the SQL Service Broker product samples from the Releases tab at Microsoft SQL Server Product Samples: Service Broker.


Running the Sample

To run the sample

1.             Open the project file ConversationPriority.ssmssqlproj in SQL Server Management Studio.

2.             Run ClientSetup.sql. This script creates a client database and the Service Broker objects for the client services.

3.             Run ServerSetup.sql. This script creates a server database and the Service Broker objects for the server service.

4.             Run ClientSendMessages.sql at least once. This script creates dialogs and sends messages from Client1Service and Client2Service to ServerService.

5.             Run ServerReceiveLoop. This script receives and replies to messages sent to ServerService.

6.             Run ClientReceiveLoops. This scripts receives messages sent to Client1Service and Client2Service and ends the conversations at the initiator (client) endpoint.

7.             Run ServerReceiveLoop. This script ends conversations at the target (server) endpoint if an end conversation message is received.

8.             Repeat steps 4 – 7 as many times as desired.

9.             Close all previously used scripts, or make sure that they are not using the sample databases.

10.       Run ServerCleanup.sql. This script deletes the database that was created for the server service.

11.       Run ClientCleanup.sql. This script deletes the database that was created for the client service.

Notes

This sample sets up two client services in one database and a server service in another database.

Priority is set to the same values independently in both databases because this is believed to be the most common use case. However, it can be set to different values in different databases. The user is encouraged to try this and see the effects by changing the priority_level values in the broker priorities in ClientSetup.sql or ServerSetup.sql.

Priority always affects the order of message receives. This is clearly shown in this sample.

Priority only affects the order of sends if the initiator and target endpoints are on different computers or SQL Server instances (except in error cases). So it is not clearly seen in this sample. However, the steps to set up priority for cross computer or cross instance messaging are identical to the steps in this sample—there are no additional steps related to priority.

The scripts in this sample are separated between client and server scripts to allow use on separate computers or SQL Server instances. However, to support this, the user needs to add routes, master keys, permissions, and ensure connectivity between the instances.