在Spring Integration中,我需要按顺序向子流A发送消息(它将消息存储到DB中),然后发送到子流B(它使用一些数据库查找)。整个A和B执行应该在一个事务的边界内执行。
最初,使用Publish-Subscribe Channel在一个线程中为A和B提供2个订阅者。但是,有两个缺点
task-executor
属性添加到频道。因此,A和B将在不同的线程中并行执行,因此在不同的事务中执行。 那么,EIP最好在这里使用?
我正在考虑Recipient List Router但是,再次发送can't see guaranty邮件发送收件人的订单。
答案 0 :(得分:2)
order
上有一个AbstractMessageHandler
属性,用于保证订阅者订阅PublishSubscribeChannel
的权限:http://docs.spring.io/spring-integration/reference/html/messaging-channels-section.html#channel-implementations-directchannel:
订单由处理程序本身定义的可选订单值确定,如果不存在此值,则订购处理程序的订购顺序。
如果某种情况要求调度程序总是尝试调用第一个处理程序,那么每次发生错误时都会以相同的固定顺序顺序回退,不应提供负载平衡策略。换句话说,即使没有启用负载平衡,调度程序仍支持故障转移布尔属性。但是,如果没有负载平衡,处理程序的调用将始终根据其顺序从第一个开始。例如,当有一个明确的初级,二级,三级等定义时,这种方法很有效。使用命名空间支持时,任何端点上的“order”属性都将确定该命令。
AbstractDispatcher
的源代码:
private final OrderedAwareCopyOnWriteArraySet<MessageHandler> handlers =
new OrderedAwareCopyOnWriteArraySet<MessageHandler>();
还有order
XML属性描述:
<xsd:attribute name="order" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
Specifies the order for invocation when this endpoint is connected as a
subscriber to a channel. This is particularly relevant when that channel
is using a "failover" dispatching strategy. It has no effect when this
endpoint itself is a Polling Consumer for a channel with a queue.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>