Spring分布式事务涉及RMI调用可能吗?

发布于 2024-09-08 00:24:14 字数 564 浏览 3 评论 0原文

背景

我有 Spring 客户端应用程序,它使用 RMI 向两台服务器提供服务。在客户端中,我将一个实体保存到数据库(简单),并对两台服务器进行 rmi 调用,并提供该实体的详细信息。我在服务器上使用 Spring 3.0.2,客户端是一个简单的 Spring-mvc 站点。

要求

我的要求是,如果任何 rmi 调用失败,整个事务将回滚到服务器,即该实体不会保存在客户端上,并且如果任一 rmi 调用成功,则该实体也将回滚后退。

我对分布式事务比较陌生,但我想我想要一个使用 RMI 调用的类似 XA 的事务。

我确实在此处找到了关于该主题的一个很好的链接,但它没有提到调用两个时的模式远程方法调用不同的服务器。我很想在推荐阅读方面听到更多关于该主题的信息,以及有关如何使用 spring 实现这一目标的任何指示。为此可以使用事务管理器吗?

谢谢。

Background

I have Spring Client application that provisions a service to two servers using RMI. In the the client I save an entity to the database (easy) and make rmi calls to two servers with details of the entity. I am using Spring 3.0.2 on the servers and the client is a simple Spring-mvc site.

Requirements

My requirement is that if any of the rmi calls fail to the servers that the whole transaction rolls back, that is the entity is not saved on the client and if either rmi call was successful that this too rolls back.

I am relatively new to Distributed transactions, but I guess I want a XA like transaction using RMI calls.

I did find a nice link on the subject here but it does not mention the pattern for when calling two remote method calls to different servers. I would love to hear more about the subject in terms of recommended reading and also any pointers on how to achieve this using spring. Is using a transaction manager for this possible?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我乃一代侩神 2024-09-15 00:24:14

从理论上讲,这是如何处理这种情况的。首先你需要在每个节点上有几个JTA分布式事务管理器。一个充当主人,另一个充当奴隶。主站协调分布式事务到从站的提交/回滚。存在独立的 JTA 实现,例如 JOTM

Vanilla RMI 不支持传播上下文信息,例如操作的事务 ID。但我认为 RMI 有钩子,因此可以对其进行扩展以支持这一点。您可以查看 Carol

您需要使用 XAResource 来包装事务的参与者,以便他们可以加入分布式事务。主服务器需要向从服务器发送提交/回滚消息,这需要使用 XATerminator 采取相应行动。

JTA规范只是一个分布式事务管理器,事务日志中的操作记录需要由服务器完成。存在用于事务日志管理的库,例如HOWL

我认为即使使用分布式事务管理器,也不能使用 Spring 轻松地做到这一点。我曾经尝试将 RMI 与由独立客户端和多个从站控制的分布式事务一起使用。这是一篇关于它的博客文章。这相当复杂。

如果您使用带有 IIOP 的 Java EE 应用程序服务器,则可以免费获得所有这些。 IIOP 支持分布式事务传播。客户端可以是应用程序客户端容器 ,并且您可以使用 UserTransaction 控制事务。这实际上是一种罕见的情况,我认为使用应用程序服务器确实是合理的。

但话虽如此,分布式事务是复杂的事情,它可能会导致启发式故障、一个节点死亡时超时以及复杂的恢复过程。

我的最后建议是:如果可能的话,尝试找到一种不涉及分布式事务的设计。这会让你的喜欢变得更容易。

您也许可以从 BPEL 补偿机制中获得灵感。也许还有其他的错误处理和鲁棒性设计方法可以避免使用分布式事务。

Here is how this situation could be theoretically handled. First you need to have several JTA distributed transaction manager on each nodes. One acts as the master, the other as the slaves. The master coordinate the commit/rollback of the distributed transaction to the slaves. Stand alone JTA implementations exist, e.g. JOTM.

Vanilla RMI does not support propagating context information such as the transaction ID of the operation. But I think RMI has hooks so that it can be extended to support that. You can have a look at Carol.

You will need to use XAResource to wrap the participants in the transaction so that they can be enlisted in the distributed transaction. The master will need to send commit/rollback messages to the slaves, which will need to use XATerminator to act accordingly.

The JTA spec is only a distributed transaction manager, logging of the operations in a transaction log needs to be done by the servers. Library exists for transaction log management, e.g. HOWL.

I don't think Spring can be used -- even with a distributed transaction manager -- to do that easily. I tried once to use RMI with distributed transaction controlled from a stand alone client and several slaves. Here is a blog post about it. It was rather complicated.

You can get all that for free if you use a Java EE application server, with IIOP. IIOP support distributed transaction propagation. The client can be an application client container, and you can control the transactions with UserTransaction. That's actually one of the rare case, where I think using an application server is really justified.

But that said, distributed transaction are complicated things, which can lead to heuristic failures, timeout if one node dies, and complicated recovery procedures.

My last advice would then be: try to find a design which does not involve distributed transaction if possible. That will make your like a lot easier.

You can maybe draw inspiration at BPEL compensation mechanism. There are maybe other design approaches for error handling and robustness which can avoid the usage distributed transactions.

巡山小妖精 2024-09-15 00:24:14

据我所知,Spring本身并不管理分布式事务。它可以使用 JtaTransactionManager,而 JtaTransactionManager 又委托给 Java EE 服务器的事务协调器。据我了解,这种事务只能在应用程序容器中注册的数据源之间使用。

您可以尝试编写自己的 XAResource 实现(不确定这是否是最好的方法,但仍然如此)并将其注册到应用程序容器中,但 Spring 不会为您提供太多帮助。

As far as I know, Spring per se doesn't manage distributed transactions. It may use JtaTransactionManager which in its turn delegates to a Java EE server's transaction coordinator. So as far as I understand this kind of transactions available only across datasources registered in application container.

You may try to write your own XAResource implementation (not sure if it's the best way, but still) and register it in application container, but Spring won't help you much with that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文