java - 具有两个来源的 Spring 集成流程

标签 java spring spring-integration spring-annotations

我尝试创建一个流程,它从 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)

最佳答案

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

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

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

或者...只是不要对它们进行 @Bean 注释,Java DSL 会处理它们的声明!

关于java - 具有两个来源的 Spring 集成流程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44356282/

相关文章:

Spring Integration DSL : How to add the HTTP. outboundGateway header ?

spring - 在 Spring Boot 中从 FTP 发送和接收文件

spring-integration - 对集群/高可用性 IBM MQ 管理器的 Spring 集成支持

java - 如何设置 Controller 类的变量名以便所有模型 View 都可以访问该变量值?

java - java对象的动态过滤

java - TypeToken 为 void 或 null

java - LibGDX 日志记录未显示在 logcat 中

java - Spring boot创建bean错误

java - 如何在 Spring Integration Java DSL 中处理 ExecutorChannel 的错误 channel

java - 如何将 ActionListener 添加到添加到 JPanel 的 JButton?