我正在开发一个spring-boot应用程序,我需要XA来确保JPA更新和JMS消息生成全部或全部。问题是当回滚发生时,DB正在回滚,而不是JMS消息。
我使用嵌入式tomcat运行,JMS服务器是Weblogic12c。
我遵循了spring-boot documentation中的JTA指示,并添加了Atomikos(transactions-jms
,transactions-jta
,transactions-jdbc
)以及spring-boot-starter-jta-atomikos
的依赖关系。
在日志中,我可以看到Atomikos正在运行,似乎是将JPA查询添加到XA事务中,但JMS没有任何内容。
以下日志来自我执行JPA更新的代码,然后使用JMSTemplate
发送JMS消息,然后我抛出RuntimeException
:
INFO c.a.jdbc.AbstractDataSourceBean - AtomikosDataSoureBean 'dataSource': getConnection ( null )...
INFO c.a.jdbc.AbstractDataSourceBean - AtomikosDataSoureBean 'dataSource': init...
INFO c.a.i.imp.CompositeTransactionImp - addParticipant ( XAResourceTransaction: 31302E33302E36302E3137332E746D30303030313030303434:31302E33302E36302E3137332E746D31 ) for transaction 10.30.60.173.tm0000100044
INFO c.a.d.xa.XAResourceTransaction - XAResource.start ( 31302E33302E36302E3137332E746D30303030313030303434:31302E33302E36302E3137332E746D31 , XAResource.TMJOIN ) on resource dataSource represented by XAResource instance oracle.jdbc.driver.T4CXAResource@621c7c98
INFO c.a.i.imp.CompositeTransactionImp - registerSynchronization ( com.atomikos.jdbc.AtomikosConnectionProxy$JdbcRequeueSynchronization@f4a9582b ) for transaction 10.30.60.173.tm0000100044
INFO c.a.jdbc.AtomikosConnectionProxy - atomikos connection proxy for oracle.jdbc.driver.LogicalConnection@650a9087: calling prepareStatement(select prjct_rvsn_seq_num_seq.nextval from dual)...
INFO c.a.jdbc.AtomikosConnectionProxy - atomikos connection proxy for oracle.jdbc.driver.LogicalConnection@650a9087: isClosed()...
INFO c.a.jdbc.AtomikosConnectionProxy - atomikos connection proxy for oracle.jdbc.driver.LogicalConnection@650a9087: calling getWarnings...
INFO c.a.jdbc.AtomikosConnectionProxy - atomikos connection proxy for oracle.jdbc.driver.LogicalConnection@650a9087: calling clearWarnings...
INFO c.a.jdbc.AtomikosConnectionProxy - atomikos connection proxy for oracle.jdbc.driver.LogicalConnection@650a9087: close()...
INFO c.a.d.xa.XAResourceTransaction - XAResource.end ( 31302E33302E36302E3137332E746D30303030313030303434:31302E33302E36302E3137332E746D31 , XAResource.TMSUCCESS ) on resource dataSource represented by XAResource instance oracle.jdbc.driver.T4CXAResource@621c7c98
INFO c.c.ola.order.service.OrderService - Order saved of scope:FIRST with app ID:1127662
INFO c.c.o.o.s.OrderEventBroadcaster - Sending message on queue jms/AppQueue
DEBUG o.s.jms.core.JmsTemplate - Executing callback on JMS Session: weblogic.jms.client.WLSessionImpl@24cfb8e8
DEBUG o.s.j.s.d.JndiDestinationResolver - Located object with JNDI name [jms/AppQueue]
DEBUG o.s.jms.core.JmsTemplate - Sending created message: TextMessage[null, <?xml version="1.0" encoding="...]
INFO c.a.d.xa.XAResourceTransaction - XAResource.rollback ( 31302E33302E36302E3137332E746D30303030313030303434:31302E33302E36302E3137332E746D31 ) on resource dataSource represented by XAResource instance oracle.jdbc.driver.T4CXAResource@621c7c98
INFO com.atomikos.icatch.jta.Sync2Sync - afterCompletion ( STATUS_ROLLEDBACK ) called on Synchronization: org.hibernate.resource.transaction.backend.jta.internal.synchronization.RegisteredSynchronization@25385341
INFO c.a.i.imp.CompositeTransactionImp - rollback() done of transaction 10.30.60.173.tm0000100044
在我的谷歌搜索中,我看不到多少。它似乎应该起作用,但我不是在哪里丢球?
更新
以下是我创建ConnectionFactory
的方式:
@Bean
FactoryBean<ConnectionFactory> jmsConnectionFactory(final JndiTemplate jndiTemplate) {
final JndiObjectFactoryBean beanFactory = new JndiObjectFactoryBean();
beanFactory.setJndiTemplate(jndiTemplate);
beanFactory.setJndiName("jms.remoteConnectionFactory");
beanFactory.setProxyInterface(ConnectionFactory.class);
return (FactoryBean) beanFactory;
}
更新
由于日志引用weblogic.jms.client.WLSessionImpl
而不是&#34; XA&#34;在名称中,我调查了weblogic返回的内容。该实例从&#34; jms.remoteConnectionFactory&#34;是weblogic.jms.client.JMSXAConnectionFactory
,它没有实现javax.jms.XAConnectionFactory
这似乎很奇怪。我不知道为什么会这样,或者这是否有问题,但似乎可能是这样。
答案 0 :(得分:0)
我的解决方案是在sessionTransacted
上将true
设置为jmsTemplate
。
@Bean
JmsTemplate cciSitesJmsTemplate(@CciSites final ConnectionFactory connectionFactory, final JndiDestinationResolver destinationResolver) {
final JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
jmsTemplate.setDestinationResolver(destinationResolver);
// NOTE: sessionTransacted is required to join the XA transaction
jmsTemplate.setSessionTransacted(true);
return jmsTemplate;
}