简体   繁体   English

使用Oracle Streams AQ在Spring MDB中共享JMS和Hibernate事务?

[英]Sharing JMS and Hibernate transactions in a Spring MDB using Oracle Streams AQ?

I'm using Oracle 11g for my database and its Oracle Streams AQ feature as JMS implementation. 我正在使用Oracle 11g作为我的数据库,并将其Oracle Streams AQ功能用作JMS实现。

For all I know, it should be possible to implement a Spring based message-driven POJO (MDP) that uses the same data source for both transactional data access and JMS transactions -- all without XA-Transactions (IIRC, this was marketed as a feature of SpringSource Advanced Pack for Oracle). 据我所知,应该可以实现一个基于Spring的消息驱动的POJO(MDP),它使用相同的数据源进行事务数据访问和JMS事务 - 所有这些都没有XA-Transactions(IIRC,它作为一个市场销售) SpringSource Advanced Pack for Oracle的特性)。

Is this possible using Hibernate as well? 这也可以使用Hibernate吗? Ideally, my MDP would start a JMS transaction and read a message from a queue, then re-use the transaction for data access through Hibernate. 理想情况下,我的MDP将启动JMS事务并从队列中读取消息,然后通过Hibernate重新使用该事务进行数据访问。 If anything goes wrong, the JMS and database transaction would both be rolled back, without using 2-phase commit (2PC). 如果出现任何问题,JMS和数据库事务都将回退,而不使用两阶段提交(2PC)。

I'm not much of a transaction guru, so before I start digging deeper, can anyone confirm that this is possible and makes sense as well? 我不是一个交易大师,所以在我开始深入挖掘之前,任何人都可以确认这是可能的并且也有意义吗?

Update: 更新:
What I want is an implementation of the Shared Transaction Resource pattern . 我想要的是共享事务资源模式的实现 The sample code demonstrates it for ActiveMQ and JDBC, but I need to use Oracle Streams AQ and Hibernate. 示例代码演示了ActiveMQ和JDBC,但我需要使用Oracle Streams AQ和Hibernate。

Update2: The SpringSource Advanced Pack for Oracle has been open sourced as part of Spring Data JDBC and it "provides the option of using a single local transaction manager for both database and message access without resorting to expensive distributed 2-phase commit transaction management". Update2: SpringSource Advanced Pack for Oracle作为Spring Data JDBC的一部分开源 ,它“提供了使用单个本地事务管理器进行数据库和消息访问的选项,而无需采用昂贵的分布式两阶段提交事务管理”。

2PC shouldn't be necessary, as you say, since the appserver should take care of it. 正如你所说,2PC不应该是必要的,因为appserver应该处理它。 However, you'll pretty much have to use JTA (ie JavaEE container) transactions, rather than vanilla DataSource transactions, since JMS only works with JTA. 但是,您几乎必须使用JTA(即JavaEE容器)事务,而不是vanilla DataSource事务,因为JMS仅适用于JTA。

This isn't a big deal, it's just a bit more fiddly: 这不是什么大问题,只是更加繁琐:

  1. Your Spring config should use <jee:jndi-lookup/> to get a reference to your container's DataSource , and you inject that data source into your spring-managed hibernate SessionFactory. 你的Spring配置应该使用<jee:jndi-lookup/>来获取对容器的DataSource的引用,并将该数据源注入到spring管理的hibernate SessionFactory中。
  2. You then need to introduce a transaction manager into the context ( <tx:jta-transaction-manager/> should work in most app-servers). 然后,您需要在上下文中引入事务管理器( <tx:jta-transaction-manager/>应该适用于大多数应用服务器)。
  3. In your Spring JMS MessageListenerContainer , plug the above transaction manager reference into it. 在Spring JMS MessageListenerContainer ,将上面的事务管理器引用插入其中。

Does that all make sense, or should I elaborate? 这一切都有意义吗,还是我应该详细说明? This setup should ensure that the container-managed transactions are held across JMS and Hibernate interactions. 此设置确保容器管理的事务跨JMS和Hibernate交互保持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM