简体   繁体   English

Sql Server Service Broker对话组

[英]Sql Server Service Broker Conversation Groups

Can someone explain conversation groups in service broker? 有人可以解释服务经纪人中的对话组吗?

Currently, I'm using service broker to send messages from one SQL server to another. 目前,我正在使用服务代理将消息从一个SQL服务器发送到另一个SQL服务器。 On the sending server, I'm trying to correlate the messages so they are processed in serial on the receiving side. 在发送服务器上,我正在尝试关联消息,以便在接收端串行处理它们。 Based on the documentation, conversation groups seem to be a perfect fit for this, but on the receiving server, the messages get assigned to a different conversation group from the one I specified when sending the message. 根据文档,对话组似乎非常适合这种情况,但在接收服务器上,消息会被分配到与发送消息时指定的对话组不同的对话组。

I've search around the web and saw that this behavior seems to be intended ( http://social.msdn.microsoft.com/forums/en-US/sqlservicebroker/thread/baf48074-6804-43ab-844a-cb28a6dce02b/ ), but then I'm confused about the usefulness of the syntax from ( http://msdn.microsoft.com/en-us/library/ms178624.aspx ) 我在网上搜索,看到这种行为似乎是有意的( http://social.msdn.microsoft.com/forums/en-US/sqlservicebroker/thread/baf48074-6804-43ab-844a-cb28a6dce02b/ ) ,但后来我对语法的有用性感到困惑( http://msdn.microsoft.com/en-us/library/ms178624.aspx

WAITFOR( 
  GET CONVERSATION GROUP @conversation_group_id FROM [dbo].[ReceiveQueue]
)

If the conversation group doesn't come across with the message from the sender and messages sent with the same conversation group id don't have the same conversation group id on the receive side, what's the point of the code above? 如果会话组没有遇到来自发件人的邮件,并且使用相同会话组ID发送的邮件在接收方没有相同的会话组ID,那么上面代码的重点是什么?

Conversation groups are a local primitve used for locking. 会话组是用于锁定的本地原始组。 Messages within a conversation group have no order guarantees, and conversation groups do not flow across the wire. 会话组内的消息没有订单保证,并且会话组不会通过网络流动。

The message order is guaranteed by Service Broker within a conversation. 消息顺序由对话中的Service Broker保证。 So to preserve the order of corrleated messages in processing, send them on the same conversation. 因此,为了在处理过程中保留corrleated消息的顺序,请在同一个对话中发送它们。

Conversation groups are needed for groupping a set of conversations that are related to each other. 需要使用会话组来填充彼此相关的一组会话。 Both GET CONVERSATION GROUP and RECEIVE verbs guarantee that they will lock an entire converstaion group, thus preventing any other thread from processing related messages. GET CONVERSATION GROUPRECEIVE谓词都保证它们将锁定整个转换组,从而阻止任何其他线程处理相关消息。 For example consider a traveling site. 例如,考虑旅行网站。 It receives a message with a request to book a holiday package. 它会收到一条消息,其中包含预订假期套餐的请求。 As a result it initiates a conversation with a hotel booking service and sends a request to reserve a room, it initiates a conversation with an airline reservation service and asks for travel reservation, it initiates a conversation with a car rental agency service and asks for a car reservation. 因此,它启动与酒店预订服务的对话并发送预订房间的请求,它启动与航空公司预订服务的对话并要求旅行预订,它启动与汽车租赁代理服务的对话并要求汽车预订。 These three new conversation it created are all in the same group with the initial conversation that the request was received on (the application has used the WITH RELATED_CONVERSATION clause of BEGIN DIALOG on all 3 of them). 它创建的这三个新会话都在同一组中,并且接收到请求的初始会话(应用程序已在其中所有3个上使用了BEGIN DIALOGWITH RELATED_CONVERSATION子句)。 It then commits and proceed to process the messages in the queue. 然后它提交并继续处理队列中的消息。 Later responses from these 3 correlated requests start comming in, at pretty much random times. 来自这3个相关请求的后续响应开始在几乎随机的时间进入。 Say the hotel resposnse comes in first. 说酒店的resposnse先进来。 The message gets picked up by the applicaiton and it goes ahead to update the status of the request with the response from the hotel. 该消息被应用程序接收,并继续使用酒店的响应更新请求的状态。 At the same time, the airline response comes in. If another thread would be allowed to pick it up, it would try to update the status of the same request, thus resulting in blocking or even deadlock against the thread that is processing the hotel response. 同时,航空公司的响应进来。如果允许另一个线程接收它,它将尝试更新同一请求的状态,从而导致阻止甚至死锁处理酒店响应的线程。 When the hotel response is processed, the thread commits and thus unlocks the whole conversation group, allowing for any thread (including itself) to pick up the airline response and process it. 当处理酒店响应时,线程提交并因此解锁整个会话组,允许任何线程(包括其自身)接收航空公司响应并处理它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM