简体   繁体   English

队列中的事务支持(MSMQ)

[英]Transaction support in Queues (MSMQ)

I'm trying to understand the concept of transaction messaging on MSMQ as well as transaction support in wcf. 我试图理解MSMQ上的事务消息传递的概念以及wcf中的事务支持。

For Queues with transaction support, does it mean the following set of operations will be automatic? 对于具有事务支持的队列,是否意味着以下一组操作将是自动的?

  1. Client A on Machine 1 writes a row in its application database that message sent to queue. 计算机1上的客户端A在其应用程序数据库中写入一行,该消息已发送到队列。
  2. Creates/Sends a Order Create message to a queue (say MSMQ). 创建/发送定单创建消息到队列(例如MSMQ)。
  3. The MSMQ message gets picked up by Client B on Machine 2. MSMQ消息由计算机2上的客户端B接收。
  4. Client B creates an Order Row in its own application Database? 客户端B在自己的应用程序数据库中创建订单行?

If I do all the above step in a distributed transaction, does it mean all 4 steps will either fail or succeed atomically? 如果我在分布式事务中执行上述所有步骤,是否意味着所有4个步骤将自动失败或成功?

Or transaction will only apply from step 1 - 2? 或交易仅适用于步骤1-2?

Similarly, if say WCF was involved above instead of the MSMQ, will all steps be atomic ie within a transaction? 同样,如果说WCF而不是MSMQ涉及到上面,那么所有步骤是否都是原子性的,即在事务内?

Short answer: 1+2 is a transaction, then 3+4 is a second transaction. 简短的答案:1 + 2是一笔交易,然后3 + 4是第二笔交易。

The only way that 3 might conceivably be in the same transaction as 2 would be for the receiver to be in the same transaction context as the sender (ie, the same logical thread of execution). 3可能与2处于同一个事务中的唯一方式是使接收方与发送方处于同一个事务上下文中(即,相同的执行逻辑线程)。 Otherwise, as the first transaction has not been committed, the message would not yet be visible for receiving. 否则,由于尚未提交第一个事务,因此该消息尚不可见。 To propagate the transaction context from the sender to the receiver, there would have to be a second communication channel from the sender to the receiver (ie, a remote invocation), which would render the message queue redundant. 为了将事务上下文从发送方传播到接收方,必须存在从发送方到接收方的第二通信通道(即,远程调用),这将使消息队列变得多余。 But this doesn't really make sense, as receiving might even get a different message from the queue... 但这实际上没有任何意义,因为接收甚至可能会从队列中收到不同的消息...

In fact, the point of transactional MQs is precisely to decouple the sender and the receiver in two different transactions, such that the sender is not impacted by the availability and performance of the receiver, at the expense of isolation. 实际上,事务MQ的目的恰恰是在两个不同的事务中将发送方和接收方解耦,从而使发送方不受接收方的可用性和性能的影响,但要以隔离为代价。 The MQ thus provides store and forward atomicity+durability without having two different applications (1 and 4) within the same transactional context. 因此,MQ提供了存储和转发原子性+持久性,而在同一事务上下文中没有两个不同的应用程序(1和4)。 You'll have 1+2 atomically, and eventually 3+4 atomically. 您将自动获得1 + 2,最终将获得3 + 4。

With WCF you can have 1 and 4 in the same transaction, by using WS-AtomicTransactions instead of MQ. 使用WCF,通过使用WS-AtomicTransactions而不是MQ,可以在同一事务中拥有1和4。 In comparison to the MQ solution, this also gives you isolation, as you never observe the effects of 1 without the effects of 4. 与MQ解决方案相比,这还为您提供了隔离,因为您永远不会观察到1的影响而没有4的影响。

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

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