为什么初始化服务不在引号中,而目标服务在引号中?
我刚刚继承了一个使用服务代理的 SQL Server 2005 数据库(这是一个更大的项目/解决方案的一部分)。有关解决方案的一切都运行良好。我正在尝试理解服务代理 SQL,并且看到了这个语句。
BEGIN DIALOG CONVERSATION @h
FROM SERVICE foo_Init
TO SERVICE 'foo_Target'
ON CONTRACT fooContract
为什么 foo_Init 不在单引号中?我希望它会像“foo_Target”一样。
I've just inherited a SQL Server 2005 database that'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'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
FROM SERVICE 必须是当前数据库中的服务,即您可以立即使用的服务。因此,您需要通过其系统名来引用它。另一方面,服务只是“外面的东西”。当 BEGIN DIALOG 语句执行时,它甚至可能不存在。当需要发送消息时,Service Broker 路由就会发挥作用,并告诉 Service Broker“外面的东西”实际位于何处以及如何到达它。因此,仅当目标服务位于同一数据库中时,通过系统名引用目标服务(与发起程序服务一样)才有意义,但情况可能并不总是如此。
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.
来自在线书籍
来自服务 initiator_service_name
指定启动对话的服务。指定的名称必须是当前数据库中的服务名称。为发起方服务指定的队列接收目标服务返回的消息以及 Service Broker 为此会话创建的消息。
服务“目标服务名称”
指定启动对话的目标服务。 target_service_name 的类型为 nvarchar(256)。 Service Broker 使用逐字节比较来匹配 target_service_name 字符串。换句话说,比较区分大小写,并且不考虑当前排序规则。
From Books On Line
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.