使用IBM MQ和Oracle作为资源的独立spring app XA事务 [英] Standalone spring app XA transactions with IBM MQ and Oracle as resources

查看:67
本文介绍了使用IBM MQ和Oracle作为资源的独立spring app XA事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个独立的Apache骆驼应用程序(不在J2EE容器上运行).此应用程序必须能够在分布式事务中将消息从IBM MQ队列管理器路由到Oracle数据库.我的Google搜索几乎将我带到了几个地方,但是没有一个能够给我一些有关如何将所有内容组合在一起的线索.下面的链接最接近我需要的链接,但不幸的是,它不够聪明,无法让我走上正确的道路.

I am in the process of developing a stand alone Apache camel application (not running on a J2EE container). This apps needs to be capable of routing messages from an IBM MQ queue manager to an Oracle database in a distributed transaction. My google searches pretty much took me to a few places but none of those were able to give me some good clues about how to put everything together. This link below was the closest to what I need but unfortunately it is not cler enough to put me on the right path.

IBM MQManager作为XA事务Spring-jms和Spring-tx的经理

预先感谢您的输入.

推荐答案

您将需要使用JTA TransactionManager,但由于不在j2ee容器中,因此我建议使用Atomikos.

You will need to use a JTA TransactionManager, but since not being in a j2ee container i would sugest to use Atomikos.

https://github.com/camelinaction/camelinaction/tree/master/第9章/xa

在J2EE中,我的与IBM MQ-> Oracle Database一起使用的路由是,但仍应与Atomikos设置一起使用.我会说这不是解决问题的正确方法,但这是我设法使其正常工作的唯一方法-对于我的用例来说,工作足够好.

My route which is working with IBM MQ -> Oracle Database, in an J2EE yes but still should be working with Atomikos setup. I would say this isn't the proper way to to it, but it's the only way I managed to get it working - working well enough for my use case.

from(inQueue)
    .transacted()
    .setHeader("storeData", constant(false))
    .to("direct:a")
    .choice().when(header("storeData").isEqualTo(false)) // if this is true the database calls are 'successful'
    .log("Sending message to errorQueue")
    .to(errorQueue)
;

StoreDataBean storeDataBean = new StoreDataBean();
from("direct:a")
    .onException(Exception.class).handled(false).log("Rollbacking database changes").markRollbackOnlyLast().end()
    .transacted("PROPAGATION_REQUIRES_NEW")
    .bean(storeDataBean) //storeData sets the header storeData to true if no SQLException or other exceptions are thrown
    .end()
;

该提交由事务管理器处理,因此,如果我实际上在数据库提交中遇到错误,则应回滚该消息.回滚消息遇到的下一个问题是,无法像使用ActiveMQ一样设置deadLetterQueue.因此,它将回滚到传入队列.因此,我实际上像在处理数据库事务一样,它是在新事务中进行的,在调用数据库时,如果发生正常的SQLException,则会进行回滚.

The commit are handled by the transaction manager, so if I actually get an error with the database commit, it should rollback the message. Next problem that I have had with rollbacking messages is that I can't set the deadLetterQueue, as you can with ActiveMQ. So it rolls back to the incoming queue. Therefore I actually handle the database transaction as I do, it is in a new transaction, which is rollbacked in case of a normal SQLException when calling the database.

我希望这能奏效:

from(inQueue)
    .onException(Exception.class).to(errorQueue).markRollbackOnly().end()
    .bean(storeDataBean)
    .end()

我已经在社区论坛上发布了有关此内容的信息,但根本没有任何答案.

I have posted about this in the community forums but no answers at all.

这篇关于使用IBM MQ和Oracle作为资源的独立spring app XA事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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