简体   繁体   English

事务回滚和Web服务

[英]Transaction rollback and web services

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? 给出从会话bean调用两个Web服务方法的示例,如果在对两个方法的调用之间抛出异常,该怎么办? In the case of not calling the web services the transaction will rollback and no harm done. 在不调用Web服务的情况下,事务将回滚并且不会造成任何损害。 However, the web service will not rollback. 但是,Web服务不会回滚。 Of course, even with a single web service there is a problem. 当然,即使使用单一的Web服务也存在问题。 While this is a generic question I am interested in solutions having to do with EJB session beans. 虽然这是一个通用问题,但我对与EJB会话bean有关的解决方案感兴趣。

An easy and customized answer would be to add a special "rollback method" to the web service for each "real functionality" method. 一个简单而定制的答案是为Web服务为每个“真实功能”方法添加一个特殊的“回滚方法”。 What I am asking for is some standardized way to do so. 我要求的是一些标准化的方法。

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. 选项一,您可以使Web服务事务知道。 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. WS-AT和WS-BA协议是事务性Web服务的领先标准。 Unfortunately they specify the protocol only, not the language bindings. 不幸的是,他们只指定协议,而不是语言绑定。 In other words, there is no standard API at the programming language level. 换句话说,在编程语言级别没有标准API。 For Java the nearest thing is JSR-156, but it's not ready yet. 对于Java来说,最接近的是JSR-156,但还没有准备好。

Then the problem becomes: how to tie the EJB (ie JTA/XA) transaction to the WS one. 然后问题变成:如何将EJB(即JTA / XA)事务绑定到WS事务。 Since the models used by the WS-AT and XA protocols are closely related, this can be achieved by means of a protocol bridge. 由于WS-AT和XA协议使用的模型密切相关,因此可以通过协议桥实现。 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 JBoss在JavaOne上展示了它们 - 请参阅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 eg an XA database backend, to be exposed as a transactional web service. 请注意,协议桥接技术也可以反过来使用,以允许使用例如XA数据库后端的EJB作为事务性Web服务公开。

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,这是专门为此类用途而设计的Web服务事务协议。

WS-BA uses a compensation based model that is harder to program. WS-BA使用基于补偿的模型,该模型更难编程。 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. 这可能很难做到,但JBoss实习生做了一个相当不错的注释框架,允许您以最小的努力定义补偿方法并自动驱动它们。 It's not standardized, but well worth checking out if you choose this approach: http://www.jboss.org/jbosstm/baframework 它不是标准化的,但是如果你选择这种方法,那么值得一试: http//www.jboss.org/jbosstm/baframework

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. 由我所知,在这种情况下使用由Microsoft,BEA Systems和IBM开发的Web服务协调(WS-C)和Web服务 - 事务(WS-T)规范。 You can start from reading Web services transactions and A comparison of Web services transaction protocols articles provided by IBM to make it clear. 您可以从阅读Web服务事务和IBM提供的Web服务事务协议文章的比较开始,以明确它们。

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. 否则,您会遇到WS-BA标准中的问题。

Just check out 看看吧 http://www.atomikos.com/Publications/TryCancelConfirm for a detailed article. http://www.atomikos.com/Publications/TryCancelConfirm获取详细文章。 The features mentioned there are available in Atomikos ExtremeTransactions ... That product also supports classical 'ACID' style web service transactions. Atomikos ExtremeTransactions提供了那里提到的功能......该产品还支持传统的'ACID'风格的Web服务交易。

HTH HTH

Guy 家伙

Disclaimer: I work for Atomikos 免责声明:我为Atomikos工作

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

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