具有两个来源

时间:2017-06-04 16:31:24

标签: java spring spring-integration spring-annotations

我尝试创建一个流,它从两个源(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 个答案:

答案 0 :(得分:2)

嗯,你必须在那些MessageProducerSupport定义中使用它,而不是像channel("mainMessageChannel")那样:

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

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

或者......只是不要@Bean注释它们,Java DSL会关注它们的声明!