Spring Chained Transaction Manager 与 Atomikos [英] Spring Chained Transaction Manager versus Atomikos

查看:35
本文介绍了Spring Chained Transaction Manager 与 Atomikos的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个分布式事务,我必须以某种方式管理它们

Hi I have a distributed transactions and I have to manage them somehow

同样在 Spring 生态系统中 ChainedTransactionManager 可以做到这一点,另一方面在 Spring 文档中 Atomikos 可以用于分布式事务

Also in spring ecosystem ChainedTransactionManager can do that on the other hand in spring document Atomikos can be used for distributed transactions

https://docs.spring.io/spring-boot/docs/2.1.6.RELEASE/reference/html/boot-features-jta.html

我应该使用哪个?我更喜欢留在 spring 库中,但 Atomikos 远不止 spring 事务管理器?如果有人同时使用它们,可以比较利弊

Which one I should use?I prefer to stay in spring librarys but Atomikos is much more than spring transaction manager?If someone use them both,Can compare pros and cons

推荐答案

使用 Atomikos 是一个更好的整体解决方案.ChainedTransactionManager 是您在某些情况下可以使用的东西.它所做的假设在 javadocs 中有说明:

Using Atomikos is a better overall solution. The ChainedTransactionManager is something you can use in some cases. The assumption it makes are stated in the javadocs:

PlatformTransactionManager 实现,用于协调事务创建、提交和回滚到委托列表.使用此实现假设导致事务回滚的错误通常发生在事务完成之前或最内部 PlatformTransactionManager 的提交期间.

PlatformTransactionManager implementation that orchestrates transaction creation, commits and rollbacks to a list of delegates. Using this implementation assumes that errors causing a transaction rollback will usually happen before the transaction completion or during the commit of the most inner PlatformTransactionManager.

配置的实例将按照给定的顺序启动事务,并以相反的顺序提交/回滚,这意味着最有可能破坏事务的 PlatformTransactionManager 应该是配置列表中的最后一个.在提交期间抛出异常的 PlatformTransactionManager 将自动导致剩余的事务管理器回滚而不是提交.

The configured instances will start transactions in the order given and commit/rollback in reverse order, which means the PlatformTransactionManager most likely to break the transaction should be the last in the list configured. A PlatformTransactionManager throwing an exception during commit will automatically cause the remaining transaction managers to roll back instead of committing.

提交一个事务而另一个失败的可能性仍然存在于 ChainedTransactionManager.

The chance of committing one transaction and the other one failing still remains with ChainedTransactionManager.

在两个数据库上使用 Atomikos 是一个真正的分布式事务全有或全无.但这也会产生一些影响应用程序支持的后果,例如当 TX 在一个 DB 上完全提交并在另一个 DB 上准备好时,应用程序崩溃.您需要确保您的应用程序可以从此场景中恢复.通常,当应用重新启动时,TX 会在第二个 DB 上完全提交,但这可能不会发生.

Using Atomikos is a real distributed transaction all or nothing on both databases. But this also has some consequences that can affect the support of the application, for example when the TX is fully commited on one DB and prepared on the other, and at that point the application crashes. You'll need to ensure that your application can recover from this scenario. Usually the TX would be fully commited on the second DB when the app is restarted, but that might not happen.

那么哪一个是正确的呢?视情况而定.

So which one is the right one? It depends.

这篇关于Spring Chained Transaction Manager 与 Atomikos的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆