1

我有以下Spring Integration配置。我在这里做的是dequeuing来自主题的消息,并在转换后将其发送到某个 HTTP 位置。

JMS Connection Factory配置如下:

<bean id="inboundCF" 
class="org.springframework.jms.connection.CachingConnectionFactory">
    <constructor-arg index="0">
        <jee:jndi-lookup jndi-name="java:comp/resource/ABC_AQ/XATopicConnectionFactories/XATCF" />
    </constructor-arg>
    <property name="sessionCacheSize" value="3" />
</bean>
<bean id="txInboundCF"
class="org.springframework.jms.connection.TransactionAwareConnectionFactoryProxy">
    <property name="targetConnectionFactory" ref="inboundCF" />
<property name="synchedLocalTransactionAllowed" value="true" />
</bean>

并且Message Listener Container配置如下:

<bean id="jmsInboundContainer"
class="org.springframework.jms.listener.DefaultMessageListenerContainer"
destroy-method="destroy">
    <property name="connectionFactory" ref="txInboundCF" />
    <property name="destination" ref="inboundDestination" />
    <property name="pubSubDomain" value="true" />
    <property name="sessionTransacted" value="true" />
    <property name="errorHandler" ref="errorHandlerService" />
    <property name="subscriptionDurable" value="true" />
    <property name="durableSubscriptionName" value="mySub" />
    <property name="cacheLevel" value="3" />
</bean>
<int-jms:message-driven-channel-adapter channel="jmsInChannel"
container="jmsInboundContainer" acknowledge="transacted" />

并且HTTP outbound adapter配置如下:

<int-http:outbound-channel-adapter channel="httpOutChannel" url="http://www.example.com/test" http-method="POST" charset="UTF-8" />

在快乐的情况下它工作正常。但是,它不会回滚 http post 消息,而是回滚 jms 消息topic,以防之后发生任何异常。所以,http:outbound-channel-adapter是不参与全局事务。

我怎样才能做到这一点。Appricate 在这方面的任何帮助。

其次,我可以在我的日志文件中找到以下日志条目,但消息正在成功出列。

[23/09/2013 14:27:51] WARN [Thread-102] CachingConnectionFactory.onException(301) | Encountered a JMSException - resetting the underlying JMS Connection
javax.jms.JMSException: java.sql.SQLException: ORA-00942: table or view does not exist

at oracle.jms.AQjmsExceptionListener.run(AQjmsExceptionListener.java:222)
[23/09/2013 14:27:51] WARN [jmsInboundContainer-9] DefaultMessageListenerContainer.handleListenerSetupFailure(821) | Setup of JMS message listener invoker failed for destination 'MY_TOPIC' - trying to recover. Cause: JMS-115: Consumer is closed
4

1 回答 1

6

这不是问题<int-http:outbound-channel-adapter>。根据定义,HTTP 协议不是事务性的。因此,如果您向某个 URL 发送请求并获得 200 OK,则意味着您的请求已成功传递到远程服务器。但是 Spring Integration 为您提供了窍门:事务同步 IT 可能如下所示:

<jms:inbound-channel-adapter>
    <int:poller>
        <int:transactional synchronization-factory="syncFactory"/>
    </int:poller>
</jms:inbound-channel-adapter>

<int:transaction-synchronization-factory id="syncFactory">
      <int:after-commit channel="httpOutboundChannel"/>
</int:transaction-synchronization-factory>

<jms:inbound-channel-adapter>可能会向某个空处理程序发送消息,例如nullChannel

于 2013-09-23T11:03:41.333 回答