首页 > 解决方案 > Spring集成默认输出通道不起作用

问题描述

在我的应用程序中,我试图根据从服务方法返回的 http 状态值进行路由,其余的 http 状态将被路由到默认错误通道。但是这个默认映射不起作用,

@Bean
public IntegrationFlow bridgeFlow() {
    return IntegrationFlows.from(ApplicationConfiguration.QUEUE_CHANNEL)
            .bridge(e -> e.poller(Pollers.fixedDelay(2500).maxMessagesPerPoll(MAX_MSG_PER_POLL)))
            .handle(someService, "someMethod")
            .route(router())                
            .get();
}

public ExpressionEvaluatingRouter router() {
    ExpressionEvaluatingRouter router = new ExpressionEvaluatingRouter("headers['httpStatus']");
    router.setChannelMapping("422", REJECTED_QUEUE_CHANNEL);
    router.setChannelMapping("202", "nullChannel");
    router.setChannelMapping("201", "nullChannel");
    router.setDefaultOutputChannelName(ORR_FAILED_QUEUE_CHANNEL);// When I receive other status codes it should go into this channel. But it's not going and throwing a runtime exception when a status code other than these is received.
    return router;
}

我尝试将默认频道放在 .route(router()).channel(ORR_FAILED_QUEUE_CHANNEL) 和 .route(router()).handle(ORR_FAILED_QUEUE_CHANNEL) 之后。但它在 bean 初始化期间失败,说“currentComponent”(org.springframework.integration.router.ExpressionEvaluatingRouter@1ca574db)是单向“MessageHandler”,不适合配置“outputChannel”。这是集成流程的结束。

标签: springspring-integrationspring-integration-dsl

解决方案


您缺少false在路由器上将此选项设置为:

/**
 * Specify whether this router should ignore any failure to resolve a channel name to
 * an actual MessageChannel instance when delegating to the ChannelResolver strategy.
 * @param resolutionRequired true if resolution is required.
 */
public void setResolutionRequired(boolean resolutionRequired) {

还有一个关于此事的文档:https ://docs.spring.io/spring-integration/docs/current/reference/html/message-routing.html#router-common-parameters


推荐阅读