如何使Spring Integration HTTP出站通道适配器参与全局事务

Ahs*_*hah 1 java jms message-queue http-post spring-integration

我有以下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>
Run Code Online (Sandbox Code Playgroud)

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" />
Run Code Online (Sandbox Code Playgroud)

HTTP outbound adapter配置如下:

<int-http:outbound-channel-adapter channel="httpOutChannel" url="http://www.example.com/test" http-method="POST" charset="UTF-8" />
Run Code Online (Sandbox Code Playgroud)

在情节愉快的情况下工作正常.但是它没有回滚http post消息,但是topic在之后发生任何异常的情况下jms消息正在回滚.所以,http:outbound-channel-adapter不参与全球交易.

我怎样才能做到这一点.在这方面提供任何帮助.

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

[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
Run Code Online (Sandbox Code Playgroud)

Art*_*lan 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>
Run Code Online (Sandbox Code Playgroud)

<jms:inbound-channel-adapter>可以向一些空的处理程序发送消息,例如nullChannel