简体   繁体   English

在JPAOutboundGateway中使用事务和请求处理程序建议链的正确方法

[英]Right way to use transactional and request-handler-advice-chain in a JPAOutboundGateway

I've got for a JPA Outbound-channel-adapter both transactional and request-handler-advice-chain. 我已经为事务处理和请求处理程序建议链提供了JPA Outbound-channel-adapter。 In the advice-chain I try to log the Exception, when it happens. 在通知链中,我尝试记录异常发生的时间。 It iss not logged, but I know that it actually happend since the Message was sent to failover clickDbFailoverChannel . 它没有记录,但是我知道它实际上是在消息发送到故障转移clickDbFailoverChannel之后发生的。 What can be a problem with it? 有什么问题吗? Is it a bug in Spring Integration? 它是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>

OK. 好。 I can guess where is your issue. 我可以猜到你的问题在哪里。 The real exception to rollback the transaction is caused before an internal logic, where <request-handler-advice-chain> does the stuff. 回滚事务的真正例外是在内部逻辑之前引起的,在内部逻辑中, <request-handler-advice-chain>执行该操作。 That's why your ExpressionEvaluatingRequestHandlerAdvice doesn't get a failure message. 这就是为什么您的ExpressionEvaluatingRequestHandlerAdvice没有收到失败消息的原因。

To workaround your rollback issue, you should replace <int-jpa:transactional> with <tx:advice> within <int-jpa:request-handler-advice-chain> . 要解决回滚问题,应在<int-jpa:request-handler-advice-chain> <int-jpa:transactional>替换为<tx:advice> <int-jpa:request-handler-advice-chain>

You should understand here that <int-jpa:transactional> is for entire MessageHandler.handleMessage , but <int-jpa:request-handler-advice-chain> is just for its part - AbstractReplyProducingMessageHandler.handleRequestMessage . 您应该在这里理解<int-jpa:transactional>适用于整个MessageHandler.handleMessage ,但是<int-jpa:request-handler-advice-chain>仅适用于它的一部分AbstractReplyProducingMessageHandler.handleRequestMessage

UPDATE 更新

TX Advice should be like this: TX建议应该是这样的:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用请求处理程序建议链和ExpressionEvaluatingRequestHandlerAdvice? - How to use request-handler-advice-chain and ExpressionEvaluatingRequestHandlerAdvice? request-handler-advice-chain中的端点信息 - Endpoint info in the request-handler-advice-chain 是否可以通过编程将“建议”添加到出站网关的请求处理程序建议链中 - Is it possible to add Advices programmatically to request-handler-advice-chain of an outboundgateway 如何添加 <int:request-handler-advice-chain /> 在Spring Integration FTP入站通道适配器中 - How to add <int:request-handler-advice-chain /> in Spring Integration FTP Inbound Channel Adapter 为链中的每个处理程序分配一个不同的错误处理程序 - assigning a different error handler to each handler in a chain AWS出站通道适配器上的建议处理程序 - advice handler on aws outbound channel adapter Spring集成消息处理程序链使用? - Spring integration Message handler chain usage? Spring 集成:在处理程序拒绝事务上下文之前调用转换器 - Spring Integration: Calling transformer before handler denies transactional context Spring集成:使用adice-chain时,Jdbc-inbound-adapter是否具有事务性 - Spring Integration: Jdbc-inbound-adapter is it transactional when using adice-chain 如何在Java配置中正确定义Spring Integration JpaOutboundGateway? - How properly define Spring Integration JpaOutboundGateway in Java Configuration?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM