事务回滚和 Web 服务

发布于 2024-07-11 06:24:27 字数 255 浏览 4 评论 0原文

给定一个从会话 bean 调用两个 Web 服务方法的示例,如果在两个方法的调用之间抛出异常怎么办? 在不调用 Web 服务的情况下,事务将回滚并且不会造成任何损害。 但是,Web 服务不会回滚。 当然,即使只有一个 Web 服务也存在问题。 虽然这是一个通用问题,但我对与 EJB 会话 bean 有关的解决方案感兴趣。

一个简单且定制的答案是为每个“实际功能”方法向 Web 服务添加一个特殊的“回滚方法”。 我所要求的是某种标准化的方法来做到这一点。

Given an example of calling two web services methods from a session bean, what if an exception is thrown between the calls to two methods? In the case of not calling the web services the transaction will rollback and no harm done. However, the web service will not rollback. Of course, even with a single web service there is a problem. While this is a generic question I am interested in solutions having to do with EJB session beans.

An easy and customized answer would be to add a special "rollback method" to the web service for each "real functionality" method. What I am asking for is some standardized way to do so.

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

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

发布评论

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

评论(3

橘和柠 2024-07-18 06:24:27

许多技术正在不断发展,但问题仍然很前沿,标准化过程尚未为我们提供完全可移植的解决方案。

选项一,您可以使 Web 服务事务感知。 当然,这假设您可以控制它们,尽管在某些情况下为非事务服务编写事务感知代理也是一种选择。

WS-AT 和 WS-BA 协议是事务性 Web 服务的领先标准。 不幸的是,他们只指定协议,而不指定语言绑定。 换句话说,编程语言层面没有标准的API。 对于 Java,最接近的是 JSR-156,但它还没有准备好。

那么问题就变成了:如何将EJB(即JTA/XA)事务与WS 事务联系起来。 由于WS-AT和XA协议使用的模型密切相关,因此这可以通过协议桥来实现。 一些应用程序服务器仅在这些行中提供一些东西。 JBoss 在 JavaOne 上展示了他们的产品 - 请参阅 http: //anonsvn.jboss.org/repos/labs/labs/jbosstm/workspace/jhalliday/txbridge/BOF-4182.odp

请注意,协议桥接技术也可以反过来使用,以允许 EJB例如,它使用 XA 数据库后端,作为事务性 Web 服务公开。

然而,两阶段提交事务使用的锁定模型实际上只适用于同一控制域中的短期事务。 如果您的服务在同一家公司的数据中心运行,您可能会逃脱惩罚。 对于更广泛的分发,无论是地理分布还是管理分布,您可能需要考虑 WS-BA,这是一种专门为此类用途而设计的 Web 服务事务协议。

WS-BA 使用基于补偿的模型,该模型更难编程。 它本质上基于您提到的技术:通过调用补偿方法来撤销服务方法的效果。 这可能很难做到,但 JBoss 实习生做了一个相当不错的注释框架,允许您以最少的努力定义补偿方法并自动驱动它们。 它不是标准化的,但如果您选择这种方法,则非常值得检查:http://www.jboss.org/jbosstm/baframework/index.html jboss.org/jbosstm/baframework

A number of techniques are evolving, but the problem is still sufficiently cutting edge that the standardization process has not yet provided us with a totally portable solution.

Option one, you can make the web services transaction aware. This of course assumes you have control over them, although writing a transaction aware proxy for non-transactional services is also an option in some cases.

The WS-AT and WS-BA protocols are the leading standards for transactional web services. Unfortunately they specify the protocol only, not the language bindings. In other words, there is no standard API at the programming language level. For Java the nearest thing is JSR-156, but it's not ready yet.

Then the problem becomes: how to tie the EJB (i.e. JTA/XA) transaction to the WS one. Since the models used by the WS-AT and XA protocols are closely related, this can be achieved by means of a protocol bridge. Several app servers provide something alone these lines. JBoss presented theirs at JavaOne - see http://anonsvn.jboss.org/repos/labs/labs/jbosstm/workspace/jhalliday/txbridge/BOF-4182.odp

Note that the protocol bridging technique can also be used the other way around, to allow an EJB that uses e.g. an XA database backend, to be exposed as a transactional web service.

However, the locking model used by two phase commit transactions is really only suitable for short lived transactions in the same domain of control. If your services run in the same company datacenter you'll probably get away with it. For wider distribution, be it geographical or administrative, you probably want to look at WS-BA, a web service transactions protocol specifically designed for such use.

WS-BA uses a compensation based model that is harder to program. It's essentially based on the technique you mention: the effect of service methods is undone by calling a compensation method. This can be tricky to get right, but a JBoss intern did a rather nice annotation framework that allows you to define compensation methods with minimal effort and have them driven automatically. It's not standardized, but well worth checking out if you choose this approach: http://www.jboss.org/jbosstm/baframework

云之铃。 2024-07-18 06:24:27

据我所知,Microsoft、BEA Systems 和 IBM 开发的 Web 服务协调 (WS-C) 和 Web 服务事务 (WS-T) 规范就用于此类情况。 您可以从阅读 Web 服务事务IBM 提供的 Web 服务事务协议比较文章,以明确这一点。

Web Services-Coordination (WS-C) and Web Services-Transaction (WS-T) specifications developed by Microsoft, BEA Systems and IBM are used in such cases as I know. You can start from reading Web services transactions and A comparison of Web services transaction protocols articles provided by IBM to make it clear.

无远思近则忧 2024-07-18 06:24:27

实际上,您通常不仅需要自定义回滚方法,还需要自定义提交方法。 否则,您会遇到 WS-BA 标准中出现的问题。

只需查看 http://www.atomikos.com/Publications/TryCancelConfirm 查看详细文章。 提到的功能可在 Atomikos ExtremeTransactions 中找到...该产品还支持经典的“ACID”风格的网络服务交易。

HTH

Guy

免责声明:我为 Atomikos 工作

Actually, you usually don't just need a custom rollback method but also a custom commit method. Otherwise, you get into problems like those found in the WS-BA standard.

Just check out http://www.atomikos.com/Publications/TryCancelConfirm for a detailed article. The features mentioned there are available in Atomikos ExtremeTransactions... That product also supports classical 'ACID' style web service transactions.

HTH

Guy

Disclaimer: I work for Atomikos

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