有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何从两个MessageProducerSpec创建Spring集成流?

我正在使用Spring集成,Java DSL(1.1.3版) 我的org.springframework.integration.dsl.IntegrationFlow定义如下

 return IntegrationFlows.from(messageProducerSpec) 
            .handle(handler) 
            .handle(aggregator) 
            .handle(endpoint) 
            .get();
    }

messageProducerSpecorg.springframework.integration.dsl.amqp.AmqpBaseInboundChannelAdapterSpec的实例

我希望我的集成流使用来自两个独立的messageProducerSpecs(两个独立的SimpleMessageListenerContainers,每个使用不同的ConnectionFactory)的消息。如何从多个messageProducerSpec构建集成流?我看不到任何集成组件能够使用来自多个源的消息


共 (1) 个答案

  1. # 1 楼答案

    在Spring集成中没有理由这么做

    始终可以将不同的端点输出到同一个MessageChannel

    因此,对于所有这些messageProducerSpec,你应该有几个简单的IntegrationFlow,并用相同的通道完成它们,其中也应该是从该通道监听的主流:

    @Bean
    public IntegrationFlow producer1() {
          return IntegrationFlows.from(messageProducerSpec1) 
            .channel("input") 
            .get();
    } 
    
    @Bean
    public IntegrationFlow producer2() {
          return IntegrationFlows.from(messageProducerSpec2) 
            .channel("input") 
            .get();
    } 
    
    ...
    
    @Bean
    public IntegrationFlow mainFlow() {
          return IntegrationFlows.from("input") 
            .handle(handler) 
            .handle(aggregator) 
            .handle(endpoint) 
            .get();
    }