Spring、XA 和 WebSphere

发布于 2024-10-25 14:33:03 字数 1469 浏览 7 评论 0原文

我正在尝试让 XA 事务在 WebSphere v7 内的 Spring v3 应用程序中工作。

我的应用程序上下文显示:

<bean id="jmsConnectionFactory" 
        class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jms/MQConnectionFactory"/>
    <property name="resourceRef" value="true"/>
</bean>

<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory" ref="jmsConnectionFactory"/>
</bean>

<jee:jndi-lookup id="myDB" jndi-name="jdbc/myDB"/>

<bean id="txManager"
    class="org.springframework.transaction.jta.WebSphereUowTransactionManager" />

<tx:annotation-driven transaction-manager="txManager"/>

我正在引用这篇文章,上面写着混入 UOW txn 管理器,就可以了。但事实并非如此。相反,在以下代码中,消息被破坏性地读取,并且在引发异常时回滚。

事务逻辑是(在scala中):

@Transactional(rollbackFor = Array(classOf[Throwable]))
def processNextMessage(category: String) = {
  val maybeMessage = readNextMessage(category) // <- this is a destructive read

  for (message <- maybeMessage) {
    // this is temporary code for testing
    throw new RuntimeException("blaaaaaah")
    // end temporary code

    // sendToQueue(message, queue)
    // writeToMessageStore(message)
  }
}

任何人都可以建议我如何将WebSphere的JTA事务管理器与Spring一起使用?

I am trying to get XA transactions working in a Spring v3 application inside WebSphere v7.

My App Context reads:

<bean id="jmsConnectionFactory" 
        class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jms/MQConnectionFactory"/>
    <property name="resourceRef" value="true"/>
</bean>

<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory" ref="jmsConnectionFactory"/>
</bean>

<jee:jndi-lookup id="myDB" jndi-name="jdbc/myDB"/>

<bean id="txManager"
    class="org.springframework.transaction.jta.WebSphereUowTransactionManager" />

<tx:annotation-driven transaction-manager="txManager"/>

I'm referencing this article that says mix in the UOW txn manager and you'll be fine. But it doesn't work that way. Instead, in the following code, the message is destructively read and is not rolled back when an exception is thrown.

The transactional logic is (in scala):

@Transactional(rollbackFor = Array(classOf[Throwable]))
def processNextMessage(category: String) = {
  val maybeMessage = readNextMessage(category) // <- this is a destructive read

  for (message <- maybeMessage) {
    // this is temporary code for testing
    throw new RuntimeException("blaaaaaah")
    // end temporary code

    // sendToQueue(message, queue)
    // writeToMessageStore(message)
  }
}

Can anyone advise how I can use WebSphere's JTA transaction manager with Spring?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眸中客 2024-11-01 14:33:03

首先,我真的很想看到 readNextMessage 的代码,因为这可能是罪魁祸首。

队列连接工厂是否设置为 XA 资源。您正在尝试使用 JTA 进行事务,因此据我所知您需要相应地配置消息 qcf。

您不必为事务设置 JmsTemplate,因为这些事务由 QueueConnectionFactory 处理。

附带说明:如果您只是处理 mq,则可以跳过 UOW JTA 提供程序并使用事务处理 JMS 会话,这应该可以正常工作。

First of all, I would really like to see the code for readNextMessage as that may be the culprit.

Is the queue connection factory set up as an XA resource. You are trying to use JTA for transactions, so as far as I know you need to configure the message qcf accordingly.

You do not have to setup the JmsTemplate for transactions, as these are handled by the QueueConnectionFactory.

On a side note: if you are just dealing with mq, you can skip the UOW JTA provider and use transacted JMS sessions, which should work fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文