JDBC和JMS的Spring的事务控制同步 [英] Spring Transaction Synchonization of JDBC and JMS

查看:647
本文介绍了JDBC和JMS的Spring的事务控制同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经运行在JBoss上的弹簧web应用程序当前配置为使用而HibernateTransactionManager为DB交易及一个JmsTransactionManager为JMS。因为我们用骆驼和ActiveMQ的JMS,我们的数据库是DB2。在一个交易,我需要写一个数字记录到数据库中,并发送两个异步JMS消息。在JMS消息是事件通知,我只希望当数据库事务提交他们发送。

I have a spring web app running on jboss that is currently configured to use the HibernateTransactionManager for db transactions and the JmsTransactionManager for jms. For jms we use Camel and ActiveMQ, our database is DB2. Within a transaction I need to write a number of records to the database and send two asynchronous jms messages. The jms messages are event notifications and I only want them to be sent if the database transaction commits.

我愿意接受与经纪人后,JDBC事务已经提交了(因此没有发送邮件,但分贝承诺),所以我不认为我需要适当的XA失败的沟通的风险。

I am willing to accept the risk of the communication with the broker failing after the jdbc transaction has already committed (and thus no messages sent but db committed) so I do not think I need proper XA.

我相信,我需要的是尽力而为的使用Spring的事务同步事务管理。

I believe that what I need is "best efforts" transaction management using spring transaction synchronization.

Spring文档排序提示中的事实,春天就会同步两个交易并提交JDBC事务一直致力于后才JMS事务 - 但我不认为这是很清楚的。 Spring文档这里<一个href=\"http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/transaction.html#tx-resource-synchronization\">http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/transaction.html#tx-resource-synchronization不进入足够的细节,它是如何工作。

The spring documentation sort of hints at the fact that spring will synchronize the two transactions and commit the jms transaction only after the jdbc transaction has been committed - but I don't think it is very clear. The spring documentation here http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/transaction.html#tx-resource-synchronization doesn't go into enough detail about how it works.

我已经找到了一些其他来源的春说会做我想做的,包括下面的一些javadoc的,我已经写了一些集成测试也证明这一点。

I have found a couple of other sources that say spring will do what I want including some javadoc below, and I have written some integration tests that also show it.

<一个href=\"http://static.springsource.org/spring/docs/3.0.x/api/org/springframework/jms/support/JmsAccessor.html#setSessionTransacted%28boolean%29\">http://static.springsource.org/spring/docs/3.0.x/api/org/springframework/jms/support/JmsAccessor.html#setSessionTransacted%28boolean%29这里setSessionTransacted上的Javadoc听起来像正是我想要的。

http://static.springsource.org/spring/docs/3.0.x/api/org/springframework/jms/support/JmsAccessor.html#setSessionTransacted%28boolean%29 The javadoc on setSessionTransacted here sounds like exactly what I want.

这是我所看到的,我认为与成交套数设置为这样的真正的创建骆驼JmsConfiguration足够的:

From what I have seen I think creating the Camel JmsConfiguration with transacted set to true like this is enough:

<bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
    <property name="connectionFactory" ref="pooledConnectionFactory"/>
    <property name="transacted" value="true"/>
    <property name="concurrentConsumers" value="10"/>
</bean>

不过,我需要说服别人我是谁有点怀疑,认为我的集成测试只适用的,因为不良记录的副作用,而不是故意的春天功能工作。

However I need to convince someone I work with who is a bit skeptical and thinks that my integration test only works because of a poorly documented side effect rather than a intentional spring feature.

所以我的问题是 - 我是正确的春天可以依靠的同步交易,并始终为JDBC事务后提交JMS交易或者是不是我应该靠,你可以点我在任何官方文档说清楚一点吗?而且我想一般,这是一个很好的方法,采取或我们应该以不同的方式来管理这些交易?

So my question is - Am I correct that spring can be relied upon to synchronize the transactions and always commit the jms transaction after the jdbc transaction or is that not something that I should rely on, and could you point me at any official documentation that says that clearly? And I guess in general is this a good approach to take or should we be managing these transactions in a different way?

推荐答案

本文章可能会有所帮助的春分布式事务,使用和不使用XA 。我不认为它具体覆盖你的情况 - 发送消息+更新数据库

This article might be of help Distributed transactions in Spring, with and without XA. I don't think it covers your case specifically - sending message + updating database.

这篇关于JDBC和JMS的Spring的事务控制同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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