【问题标题】:Output channel routing输出通道路由
【发布时间】:2017-02-02 10:14:30
【问题描述】:

我正在尝试将 Spring Integration 流程从 XML 重写为 Java。我想路由通过通道发送的数据:

@Bean(name = "sendData")
public MessageChannel getSendData() {
    return MessageChannels.direct()
                          .get();
}

进入另外两个渠道:

@Bean(name = "sendDataA")
public MessageChannel getSendDataA() {
    return MessageChannels.direct()
                          .get();
}

@Bean(name = "sendDataB")
public MessageChannel getSendDataB() {
    return MessageChannels.direct()
                          .get();
}

取决于他们的可用性。

我有一个RoundRobinRouter 类来确定使用哪个输出通道。它有一个方法route,返回输出通道名称,如:

@Component
class RoundRobinRouter {
    public String route(Object payload) {
        /* implementation */
    }
}

请注意,route 方法实现实际上并不使用payload 对象。它以前放在 XML 配置中:

<int:router method="route" input-channel="sendData"
            default-output-channel="sendDataA">
    <bean
            class="com.example.RoundRobinRouter"/>
</int:router>

我已经尝试过使用 Java DSL IntegrationFlow:

@Bean
@ServiceActivator(inputChannel = "sendData",
                  outputChannel = "sendDataA")
public IntegrationFlow routeRoundRobin() {
    return router -> router.route(roundRobinRouter, "route");
}

但我在sendData.send(payload) 调用时收到错误“调度程序没有订阅者”,显然是由以下原因引起的:

org.springframework.expression.spel.SpelEvaluationException: EL1004E:(pos 8):方法调用:方法配置(com.example.DataType) 在 com.example.Integration$$Lambda$1/1018103616 类型上找不到

路由器是我的集成类中唯一的 lambda。

【问题讨论】:

    标签: java spring spring-integration spelevaluationexception


    【解决方案1】:

    好的,我开始工作了。我不确定哪个更改解决了我的问题,但这里是正确的路由器实现:

    @Bean
    public IntegrationFlow routeRoundRobin() {
        return IntegrationFlows.from(getSendData())
                               .route(roundRobinRouter, "route",
                                      r -> r.channelMapping("sendDataA",
                                                            "sendDataA")
                                            .channelMapping("sendDataB",
                                                            "sendDataB"))
                               .get();
    }
    
    @Bean(name = "sendData")
    public MessageChannel getSendData() {
        return MessageChannels.direct()
                              .get();
    }
    
    @Bean(name = "sendDataA")
    public MessageChannel getSendDataA() {
        return MessageChannels.direct()
                              .get();
    }
    
    @Bean(name = "sendDataB")
    public MessageChannel getSendDataB() {
        return MessageChannels.direct()
                              .get();
    }
    

    我将@ServiceActivatorsendData更改为IntegrationFlow,并且还为路由器添加了通道映射。

    【讨论】:

      猜你喜欢
      • 2013-12-06
      • 1970-01-01
      • 2016-12-16
      • 1970-01-01
      • 2021-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多