我想在实现轮询时使用带有事务传播的 SourcePollingChannelAdapter,以便在发生错误时回滚所有操作。方法 setTransactionSynchronizationFactory 没有评论...非常感谢您的帮助!
在 XML 中,我可以这样做:
<int:poller fixed-rate="5000">
<int:transactional transaction-manager="transactionManager" propagation="REQUIRED" />
</int:poller>
我想通过 SourcePollingChannelAdapter 和 PeriodicTrigger 以编程方式使用这样的事务,但我不知道如何。
我有这个 :
SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter();
adapter.setSource(source);
adapter.setTrigger(new PeriodicTrigger(5, TimeUnit.SECONDS));
adapter.setOutputChannel(channel);
adapter.setBeanFactory(ctx);
adapter.start();
当bean源被调用时,数据库中的一个元素被删除,一个消息被创建并在outputchannel中发送;但是,如果在输出通道之后我的流程出现错误,我希望数据库恢复并且元素回来......实际上是一个简单的事务与传播。我不明白怎么做。
输出通道是:
<int:channel id="channel" >
<int:queue />
</int:channel>
<int-http:outbound-gateway request-channel="channel"
url="http://localhost:8081/icopitole-ws/baseactive" http-method="GET"
reply-channel="reresponseVersionChannel" expected-response-type="java.lang.String" />
当 URL 没有响应时,会引发异常但不执行回滚,尽管我已经添加了 DefaultTransactionSynchronizationFactory 和 TransactionInterceptor 就像你说的那样:(