涉及RMI调用的Spring分布式事务可能吗? [英] Spring Distributed Transaction Involving RMI calls possible?

查看:167
本文介绍了涉及RMI调用的Spring分布式事务可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

后台

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

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.

要求

我的要求是,如果任何rmi调用失败整个事务回滚的服务器,即实体未保存在客户端上,如果rmi调用成功,它也会回滚。

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.

我是相对的新的分布式事务,但我想我想要一个使用RMI调用的XA事务。

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

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

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?

谢谢。

推荐答案

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

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不支持传播上下文信息,例如操作的事务ID。但我认为RMI已经挂钩,因此可以扩展它以支持它。您可以查看 Carol

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.

你需要使用 XAResource 将参与者包装在事务中,以便它们可以在分布式事务中登记。主服务器需要向从服务器发送提交/回滚消息,这需要使用 XATerminator 采取相应行动。

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.

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

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.

我不认为春天即使使用分布式事务管理器,也可以使用它来轻松完成。我尝试过一次使用RMI与分布式事务控制从一个独立的客户端和几个从属。这是关于它的博客文章。它相当复杂。

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.

如果你使用带有IIOP的Java EE应用服务器,你可以免费获得所有这些。 IIOP支持分布式事务传播。客户端可以是应用程序客户端容器 ,您可以使用 UserTransaction 控制交易。这实际上是极少数情况之一,我认为使用应用程序服务器是非常合理的。

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.

您可以从BPEL中获取灵感补偿机制。可能存在用于错误处理和鲁棒性的其他设计方法,其可以避免使用分布式事务。

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.

这篇关于涉及RMI调用的Spring分布式事务可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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