How to create Spring Integration Flow from two MessageProducerSpec?

 ̄綄美尐妖づ 提交于 2019-12-20 01:53:05

问题


I am using Spring Integration, Java DSL (release 1.1.3) I have my org.springframework.integration.dsl.IntegrationFlow defined as follows

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

messageProducerSpec is instance of org.springframework.integration.dsl.amqp.AmqpBaseInboundChannelAdapterSpec

I would like my integration flow to consume messages from TWO separate messageProducerSpecs (two separate SimpleMessageListenerContainers, each using diffrent ConnectionFactory). How is it possible to construct integrationFlow from more than one messageProducerSpec? I see no integration component that is able to consume messages from multiple sources.


回答1:


There is no reason to do that in Spring Integration.

You always can output different endpoints to the same MessageChannel.

Therefore you should have several simple IntegrationFlows for all those messageProducerSpec and finish them with the same channel, where also should be the main flow which will listen from that channel:

@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();
} 


来源:https://stackoverflow.com/questions/39577608/how-to-create-spring-integration-flow-from-two-messageproducerspec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!