Service Broker assigns priority levels to conversation endpoints. The priority levels control the priority of the operations associated with the endpoint. Each conversation has two conversation endpoints:
-
The initiator conversation endpoint associates one side of the conversation with the initiator service and initiator queue. The initiator conversation endpoint is created when the BEGIN DIALOG statement is run. The operations associated with the initiator conversation endpoint include:
-
Sends from the initiator service.
-
Receives from the initiator queue.
-
Getting the next conversation group from the initiator queue.
-
The target conversation endpoint associates the other side of the conversation with the target service and queue. The target conversation endpoint is created when the conversation is used to send a message to the target queue. The operations associated with the target conversation endpoint include:
-
Receives from the target queue.
-
Sends from the target service.
-
Getting the next conversation group from the target queue.
Service Broker assigns conversation priority levels when conversation endpoints are created. The conversation endpoint retains the priority level until the conversation ends. New priorities or changes to existing priorities are not applied to existing conversations.
Service Broker assigns a conversation endpoint the priority level from the conversation priority whose contract and services criteria best match the properties of the endpoint. The following table shows the match precedence:
|
Operation contract
|
Operation local service
|
Operation remote service
|
|---|
|
ContractName
|
LocalServiceName
|
RemoteServiceName
|
|
ContractName
|
LocalServiceName
|
ANY
|
|
ContractName
|
ANY
|
RemoteServiceName
|
|
ContractName
|
ANY
|
ANY
|
|
ANY
|
LocalServiceName
|
RemoteServiceName
|
|
ANY
|
LocalServiceName
|
ANY
|
|
ANY
|
ANY
|
RemoteServiceName
|
|
ANY
|
ANY
|
ANY
|
Service Broker first looks for a priority whose specified contract, local service, and remote service matches those that the operation uses. If one is not found, Service Broker looks for a priority with a contract and local service that matches those that the operation uses, and where the remote service was specified as ANY. This continues for all the variations that are listed in the precedence table. If no match is found, the operation is assigned the default priority of 5.
Service Broker independently assigns a priority level to each conversation endpoint. To have Service Broker assign priority levels to both the initiator and target conversation endpoints, you must ensure that both endpoints are covered by conversation priorities. If the initiator and target conversation endpoints are in separate databases, you must create conversation priorities in each database. The same priority level is usually specified for both of the conversation endpoints for a conversation, but you can specify different priority levels.
Priority levels are always applied to operations that receive messages or conversation group identifiers from a queue. Priority levels are also applied when transmitting messages from one instance of the Database Engine to another.
Priority levels are not used when transmitting messages:
-
From a database where the HONOR_BROKER_PRIORITY database option is set to OFF. For more information, see ALTER DATABASE SET Options (Transact-SQL).
-
Between services in the same instance of the Database Engine.
-
All Service Broker operations in a database are assigned default priorities of 5 if no conversation priorities have been created in the database.