2017-06-04 25 views
1

我嘗試創建一個從2個來源(1個mqtt和一個來自用戶服務交互)獲取消息的流程,並將消息生成到另一個mqtt。 事實上,我嘗試使用這樣的回答:How to crate Spring Integration Flow from two MessageProducerSpec?有兩個來源的彈簧整合流程

這裏是我的結果:

@Bean 
public IntegrationFlow mqttInFlow() { 
    return IntegrationFlows.from(mqttInbound()) 
      .channel("mainMessageChannel") 
      .get(); 
} 

@Bean 
public IntegrationFlow mqttTestMessageFlow() { 
    return IntegrationFlows.from(messageService.testInbound()) 
      .channel("mainMessageChannel") 
      .get(); 
} 

@Bean 
public IntegrationFlow mainMessageFlow() { 
    return IntegrationFlows.from("mainMessageChannel") 
      .handle(eventServiceHandler()) 
      .split(operationSplitter()) 
      .handle(mqttOutbound()) 
      .get(); 
} 

但我有以下錯誤:

java.lang.IllegalStateException: 'outputChannel' or 'outputChannelName' is required 
    at org.springframework.util.Assert.state(Assert.java:70) 
    at org.springframework.integration.endpoint.MessageProducerSupport.afterSingletonsInstantiated(MessageProducerSupport.java:136) 

回答

1

那麼,你必須使用它在那些MessageProducerSupport的定義中,不是像channel("mainMessageChannel")

@Bean 
MessageProducerSupport mqttInbound() { 
    ... 
    adapter.setOutputChannelName("mainMessageChannel"); 
    ... 
} 

@Bean 
MessageProducerSupport testInbound() { 
    ... 
    adapter.setOutputChannelName("mainMessageChannel"); 
    ... 
} 

或...只是不要@Bean對他們的註釋和Java DSL會照顧他們的聲明!