多个 IntegrationFlows 附加到网关方法中的同一请求通道

Multiple IntegrationFlows attached to the same request channel in Gateway method

鉴于我有使用 Spring 集成的应用程序并且我定义了网关:

@Component
@MessagingGateway
public interface SmsGateway {

    @Gateway(requestChannel = CHANNEL_SEND_SMS)
    void sendSms(SendSmsRequest request);
}

public interface IntegrationChannels {
    String CHANNEL_SEND_SMS = "channelSendSms";
}

我还将 IntegrationFlow 附加到 CHANNEL_SEND_SMS 频道:

@Bean
public IntegrationFlow sendSmsFlow() {
    return IntegrationFlows.from(CHANNEL_SEND_SMS)
            .transform(...)
            .handle(...)
            .get();
}

每当我从业务代码中调用 sendSms 网关方法时,sendSmsFlow 都会按预期执行。

当我想将另一个 IntegrationFlow 附加到同一个 CHANNEL_SEND_SMS 频道时,例如

@Bean
public IntegrationFlow differentFlow() {
    return IntegrationFlows.from(CHANNEL_SEND_SMS)
            .transform(...)
            .handle(...)
            .get();
}

那么这个differentFlow就不执行了

为什么会这样?

是否有任何解决方案使其适用于两种流程?

默认频道类型为DirectChannel,默认情况下消息以循环方式分发到多个订阅频道。

如果您希望每个流获取每条消息,请将 CHANNEL_SEND_SMS 声明为 PublishSubscribeChannel

这仅适用于 void 网关方法;如果有 return 类型,您将获得第一个(如果有任何异步下游处理,则为随机),其他将被丢弃。