开发者

Why is initializing service not in quotes when target service is?

开发者 https://www.devze.com 2022-12-20 06:55 出处:网络
I\'ve just inherited a SQL Server 2005 database th开发者_C百科at\'s using service broker (this is part of a bigger project/solution).Everything about the solution is working fine.I\'m trying to grok t

I've just inherited a SQL Server 2005 database th开发者_C百科at's using service broker (this is part of a bigger project/solution). Everything about the solution is working fine. I'm trying to grok the service broker SQL, and I see this statement.

BEGIN DIALOG CONVERSATION @h
FROM SERVICE foo_Init
TO SERVICE 'foo_Target'
ON CONTRACT fooContract

Why is foo_Init not in single quotes? I'd expect it to be, just like 'foo_Target'.


FROM SERVICE must be a service in a current database, i.e. something that you can get your hands on right away. Therefore you're required to refer to it by its sysname. TO SERVICE on the other hand is just "something out there". It may not even exist while the BEGIN DIALOG statement is executing. When a message needs to be sent, Service Broker routes come into play and tell Service Broker where that "something out there" is actually located and how to reach it. Therefore referring to the target service by sysname (as it is with initiator service) would make sense only if the target service was in the same database, which may not always be the case.


From Books On Line

BEGIN DIALOG [ CONVERSATION ] @dialog_handle
   FROM SERVICE initiator_service_name
   TO SERVICE 'target_service_name'
       [ , { 'service_broker_guid' | 'CURRENT DATABASE' } ] 
   [ ON CONTRACT contract_name ]
   [ WITH
   [  { RELATED_CONVERSATION = related_conversation_handle 
      | RELATED_CONVERSATION_GROUP = related_conversation_group_id } ] 
   [ [ , ] LIFETIME = dialog_lifetime ] 
   [ [ , ] ENCRYPTION = { ON | OFF }  ] ]
[ ; ]

FROM SERVICE initiator_service_name Specifies the service that initiates the dialog. The name specified must be the name of a service in the current database. The queue specified for the initiator service receives messages returned by the target service and messages created by Service Broker for this conversation.

TO SERVICE 'target_service_name' Specifies the target service with which to initiate the dialog. The target_service_name is of type nvarchar(256). Service Broker uses a byte-by-byte comparison to match the target_service_name string. In other words, the comparison is case-sensitive and does not take into account the current collation.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号