英文:
Is need separate Transaction Manager between JMS and JDBC?
问题
我在JDBC事务中遇到了问题,当出现错误时会将JMS消息返回到队列,我猜是这样的。这意味着一些消息正在被再次处理。
我的应用程序配置如下:
- 我已经像这样配置了JtaTransactionManager:
...
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<tx:jta-transaction-manager/>
....
- 并且我已经像这样配置了JMS DefaultMessageListenerContainer:
@Bean
public DefaultMessageListenerContainer jmsContainer(ConnectionFactory connectionFactory, PlatformTransactionManager transactionManager, ....) throws NamingException {
DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.setSessionTransacted(true);
container.setTransactionManager(transactionManager);
....
return container;
}
在我的情况下,当我收到一个JMS消息时,在我的代码逻辑中会出现org.springframework.dao.DataIntegrityViolationException。我通过try-catch块处理异常,我期望一切都会好起来。但是在这个时候,据我所见,消息会返回到队列并被再次处理。如果在我的代码中发生其他异常,比如IllegalStateException/RuntimeException,就不会出现这种行为。
我猜想,JDBC事务中的错误会导致JMS事务中断,尽管我处理了异常。
请告诉我,我是否正确地在JPA和JDBC上使用了一个事务管理器?
或者我是否需要为我的DataSource和JMS DefaultMessageListenerContainer使用两种不同的实现?
另外,如果我可以提供更多信息,我会这么做。
谢谢!
英文:
I faced with problem when error in JDBC transaction cause return JMS-message to queue, I guess so. It means that some message are being processed again.
My app has next configuration:
- I have configured JtaTransactionManager like this:
...
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<tx:jta-transaction-manager/>
....
- And I has configured JMS DefaultMessageListenerContainer like this:
@Bean
public DefaultMessageListenerContainer jmsContainer(ConnectionFactory connectionFactory, PlatformTransactionManager transactionManager, ....) throws NamingException {
DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.setSessionTransacted(true);
container.setTransactionManager(transactionManager);
....
return container;
}
In my case, when I receive a JMS message, in my code logic happens org.springframework.dao.DataIntegrityViolationException. I handle exception via try-catch block and I expect everything will be fine. But in this time, as I see, message return to queue and it being processed again. This behavior isn't reproduce, if in my code happens other Exception, like as IllegalStateException/RuntimeException.
And I suppose that error in JDBC transaction causes broke JMS transaction despite the fact I handle exception.
Let me know, is it correct that I use one transaction manager for JPA and JDBC?
Or I need two different implementations for my DataSource and JMS DefaultMessageListenerContainer?
Also, if I can produce more information, I will.
Thanks!
专注分享java语言的经验与见解,让所有开发者获益!
评论