【问题标题】:Right way to use transactional and request-handler-advice-chain in a JPAOutboundGateway在 JPAOutboundGateway 中使用事务和请求处理程序建议链的正确方法
【发布时间】:2014-09-16 03:13:48
【问题描述】:

我有一个 JPA Outbound-channel-adapter 交易和请求处理程序建议链。在建议链中,我尝试在异常发生时记录它。 它没有记录,但我知道它实际上是在消息被发送到故障转移 clickDbFailoverChannel 后发生的。它可能有什么问题?这是 Spring Integration 中的错误吗?

<int:channel id="clickDbWithFailoverChannelSite-1">
     <int:dispatcher load-balancer="none" task-executor="clickDbSiteRouterExecutor"/>
</int:channel>
<int:bridge input-channel="clickDbWithFailoverChannelSite-1"
     output-channel="jpaOutboundChannelSite-1" order="1" send-timeout="100" />
<int:bridge input-channel="clickDbWithFailoverChannelSite-1"
     output-channel="clickDbFailoverChannel" order="2" />
<int-jpa:outbound-channel-adapter id="jpaOutboundChannelSite-1"
     persist-mode="PERSIST" flush-size="100" entity-manager-factory="emfSite-1">
    <int-jpa:transactional transaction-manager="transactionManagerSite-1" />
    <int-jpa:request-handler-advice-chain>
        <bean class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice">
            <property name="failureChannel" ref="clickDbFailureLogger"/>
            <property name="onFailureExpression" value="#exception"/>
        </bean>
    </int-jpa:request-handler-advice-chain>
</int-jpa:outbound-channel-adapter>

【问题讨论】:

  • 抱歉,信息不足。一些 StackTrace 以查看 SI 不正确的地方。一些无法正常工作的庞然大物。它应该如何工作等等......

标签: spring-integration


【解决方案1】:

好的。我可以猜到你的问题在哪里。回滚事务的真正异常是在内部逻辑之前引起的,&lt;request-handler-advice-chain&gt; 负责处理这些事情。这就是为什么您的 ExpressionEvaluatingRequestHandlerAdvice 没有收到失败消息的原因。

要解决您的回滚问题,您应该在&lt;int-jpa:request-handler-advice-chain&gt; 中将&lt;int-jpa:transactional&gt; 替换为&lt;tx:advice&gt;

您应该在这里了解&lt;int-jpa:transactional&gt; 是整个MessageHandler.handleMessage,但&lt;int-jpa:request-handler-advice-chain&gt; 只是它的一部分 - AbstractReplyProducingMessageHandler.handleRequestMessage

更新

TX Advice 应该是这样的:

 <tx:advice transaction-manager="transactionManagerSite-1"/>
        <tx:attributes>
            <tx:method name="*"/>
        </tx:attributes>
</tx:advice>

【讨论】:

  • 好。让我从测试用例中检查一下
  • 更新了答案。对不起
  • 谢谢,没有更多的TransactionRequiredException,但不幸的是,当我关闭数据库时,我没有像以前那样在日志中从 RequestHandler 获得异常。我期望类似“无法从底层数据库获取连接!”。所以实际上它现在看起来像原来的帖子。只有 hibernate 异常得到咳嗽(即字段长度验证等),但它也适用于原始版本
  • 无论如何配置看起来已经很丑陋了。你有计划为这个问题做些更方便的事情吗?
  • 您可以将&lt;tx:advice&gt;ExpressionEvaluatingRequestHandlerAdvice 配置为单独的bean 并在此处使用&lt;beans:ref bean=""&gt;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-07-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-31
相关资源
最近更新 更多