[英]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.