事务回滚和 Web 服务 [英] Transaction rollback and web services

查看:27
本文介绍了事务回滚和 Web 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

一个简单且定制的答案是为每个真正的功能"方法向 Web 服务添加一个特殊的回滚方法".我要求的是一些标准化的方法.

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.

推荐答案

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

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.

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

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.

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

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.

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

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

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

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.

然而,两阶段提交事务使用的锁定模型实际上只适用于同一控制域中的短期事务.如果您的服务在同一个公司数据中心运行,您可能会侥幸逃脱.对于更广泛的分布,无论是地理分布还是管理分布,您可能需要查看 WS-BA,这是一种专为此类用途设计的 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 使用更难编程的基于补偿的模型.它基本上基于您提到的技术:通过调用补偿方法来撤消服务方法的效果.这可能很难做到,但 JBoss 实习生做了一个相当不错的注释框架,允许您以最少的努力定义补偿方法并自动驱动它们.它不是标准化的,但如果您选择这种方法,非常值得一试:http://www.jboss.org/jbosstm/baframework

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

这篇关于事务回滚和 Web 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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