【问题标题】:Spring, XA and WebSphereSpring、XA 和 WebSphere
【发布时间】:2011-03-24 05:48:56
【问题描述】:

我正在尝试让 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"/>

我引用了this article,它说在 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)
  }
}

谁能建议我如何在 Spring 中使用 WebSphere 的 JTA 事务管理器?

【问题讨论】:

  • jmsTemplate使用的connectionFactory是如何配置的? jmsTemplate 的 transactionManager 属性设置了吗?
  • jmsTemplate 上没有 transactionManager 属性。而且我读到注释方法意味着不需要显式注入。

标签: spring websphere xa transactionmanager


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 2015-05-26
    • 2013-01-09
    • 1970-01-01
    • 1970-01-01
    • 2014-12-18
    • 2012-12-19
    • 2015-06-06
    • 1970-01-01
    • 2012-12-31
    相关资源
    最近更新 更多