简体   繁体   English

JMS本地事务与TransactionManager

[英]JMS Local transactions vs TransactionManager

I have been looking into the Jms API lately and I am not certain I understand the local vs transaction manager differences. 我最近一直在研究Jms API,但不确定我是否了解本地与事务管理器之间的差异。

Scenario 1: 方案1:

Consume message from Jms broker, process the message and commit transaction once processing succeeds otherwise rollback. 使用来自Jms代理的消息,处理该消息,一旦处理成功,则提交事务,否则回滚。

Scenario 2: 方案2:

I want to proxy messages from one broker to another broker but I do not want to use XA transactions due to its slow nature. 我想将消息从一个经纪人代理到另一个经纪人,但是由于其缓慢的特性,我不想使用XA事务。 So the idea is to start a transaction for the broker I am consuming from and then within that transaction start a second transaction for the broker I am producing to and then commit the two transactions in succession. 因此,想法是为我正在使用的代理开始事务,然后在该事务中为我要生成的代理开始第二个事务,然后依次提交这两个事务。 Lets ignore the issue of the duplication risk in this scenario which can be mitigated 让我们忽略这种情况下的重复风险问题,该问题可以缓解

What exactly is the difference to between using JMS commit(), rollback() APIs (Aka Local Transactions) vs using a Transaction Manager such as Spring's PlatformTransactionManager class? 使用JMS commit(),rollback()API(又称本地事务)与使用事务管理器(例如Spring的PlatformTransactionManager类)之间到底有什么区别? Is a transaction manager necessary in the second scenario at all and why so/not? 在第二种情况下,是否需要交易管理器,为什么/不是?

Transaction managers are going to ensure that the transaction spanning servers is either going to be committed together or rolled-back together. 事务管理器将确保跨事务的服务器将一起提交或回滚。

Manually managing separate transactions opens up holes, such as Server A transaction committed but Server B can't be because of any number of error conditions (network, application failure, etc.). 手动管理单独的事务会带来一些漏洞,例如服务器A提交的事务,但服务器B不能这样做是因为有许多错误情况(网络,应用程序故障等)。 There are many scenarios like this where a transaction manager mitigates the issues. 在许多类似情况下,事务管理器可以缓解这些问题。

It might be that your application is idempotent and can handle seeing the same messages multiple times and handle it correctly or that there are process flows issues that can correct for bad situations, in which case you're probably fine. 可能是您的应用程序是幂等的,可以处理多次看到相同的消息并正确处理它,或者可能存在可以纠正不良情况的流程问题,在这种情况下,您可能还可以。

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

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