gpt4 book ai didi

transactions - 将事务保留在 Spring Integration 流程中

转载 作者:行者123 更新时间:2023-12-03 06:21:05 26 4
gpt4 key购买 nike

入站网关:

<int-http:inbound-gateway   id="inbound.gateway"
request-channel="transactional.channel.input"
reply-channel="channel.output"
error-channel="channel.error"
request-payload-type="java.lang.String"
</int-http:inbound-gateway>

建议定义:

<tx:advice id="advice">
<tx:attributes>
<tx:method name="send" propagation="REQUIRES_NEW" rollback-for="MyClassException"/>
</tx:attributes>
</tx:advice>

建议配置:

<aop:config>
<aop:advisor advice-ref="advice" pointcut="bean(transactional.channel.input)"/>
</aop:config>

需要交易的链:

<int:chain input-channel="transactional.channel.input" output-channel="non.transactional.channel.input>
<int:service-activator ref="v1.registerUser.service" method="registerUser"/>
<int:service-activator ref="v1.saveObject.service" method="saveObject"/>
</int:chain>

需要先执行交易才能获取最后交易链步骤中生成的对象ID的链:

<int:chain input-channel="non.transactional.channel.input" output-channel="channel.output">
<int:service-activator ref="v1.getObjectId.service" method="getObjectId"/>
<int:object-to-json-transformer/>
</int:chain>

有了这个简化的上下文,当我访问 getObjectId 服务中的 id 时,事务尚未执行。

因此事务似乎是在入站网关输出级别提交的。

最佳答案

无需编写任何 Java 代码,还有一个令人惊奇的技巧:

<channel id="input"/>

<aop:config>
<aop:advisor advice-ref="txAdvice" pointcut="bean(input)"/>
</aop:config>

<tx:advice id="txAdvice">
<tx:attributes>
<tx:method name="send"/>
</tx:attributes>
</tx:advice>

这样,所有直接单线程消息流都将被包装到发送到 channel 输入的消息的 TX

关于transactions - 将事务保留在 Spring Integration 流程中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18901510/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com