gpt4 book ai didi

java - 为顺序子流调用选择适当的 EIP

转载 作者:行者123 更新时间:2023-11-30 08:32:07 24 4
gpt4 key购买 nike

Spring Integration我需要按顺序将消息发送到子流 A(它将消息存储到数据库中),然后再发送到子流 B(它使用一些数据库查找)。整个 A 和 B 执行应该在一个事务的边界内执行。

最初,Publish-Subscribe Channel在一个线程中使用了 A 和 B 的 2 个订阅者。但是,有两个缺点

  1. 没有保证订阅者执行的顺序
  2. 很容易添加task-executor channel 的属性。因此,A 和 B 将在不同的线程中并行执行,从而在不同的事务中执行。

那么,什么EIP用在这里比较好?

我在考虑Recipient List Router但是,再一次,can't see guaranty收件人的消息发送顺序。

最佳答案

AbstractMessageHandler 上有一个order 属性,它保证订阅者将如何订阅到PublishSubscribeChannel:http://docs.spring.io/spring-integration/reference/html/messaging-channels-section.html#channel-implementations-directchannel :

The order is determined by an optional order value defined on the handlers themselves or, if no such value exists, the order in which the handlers are subscribed.

If a certain situation requires that the dispatcher always try to invoke the first handler, then fallback in the same fixed order sequence every time an error occurs, no load-balancing strategy should be provided. In other words, the dispatcher still supports the failover boolean property even when no load-balancing is enabled. Without load-balancing, however, the invocation of handlers will always begin with the first according to their order. For example, this approach works well when there is a clear definition of primary, secondary, tertiary, and so on. When using the namespace support, the "order" attribute on any endpoint will determine that 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>

关于java - 为顺序子流调用选择适当的 EIP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40271525/

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