开发者

Should I use HornetQ JMS API to integrate with Spring TransactionManager?

I have a basic doubt regarding Transactions and the HornetQ native API.

If my application is Spring-based, with Spring managed transactions, how should I configure HornetQ to participate in the same transaction managed by Spring (AOP)?

Using the JMS API I guess it's fairly obvious, since Spring considers JMS resources as transactional.

But I don't know how to do it correctly using the nativa API. Could someone shed 开发者_JS百科a light on this problem?

Many thanks!


HornetQ supports XA on the core API, they are just resources.

You should be able to enlist these resources on Spring if that's just using regular XA API.

http://docs.jboss.org/hornetq/2.2.5.Final/api/org/hornetq/api/core/client/ClientSession.html

I'm not sure though how that integration is done on Spring. If there's anything not working it could (and should) be fixed or improved on a spring-integration module.


Not sure if I understand correctly, but if you're trying to simply do declarative transaction managment using Spring and the @Transactional annotation for JUST JMS, then simply use the <tx:annotation-driven transaction-manager = "myTransactionManager" /> and then - for the "myTranactionManager," register a bean of type JmsTransactionManager, e.g.,

@Bean public PlatformTransactionManager myTranactionManager (){ 
  return new JmsTransactionManager( this.connectionFactory());
} 

Now, you can use the annotation as normal and the JMS interactions will be wrapped in a transaction

@Transactional
public void doSomethingWithJms(){ 
  jmsTemplate.send(...);
  jmsTemplate.convertAndSend(...)
}

If your goal is to work with MULTIPLE resources, e.g., JMS and JDBC, then you need to use JTA. To see how to setup JTA (for JPA and JMS), check out this blog post http://blog.springsource.com/2011/08/15/configuring-spring-and-jta-without-full-java-ee/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜