Spring Integration DSL:执行routeToRecipients后不会执行其他组件

时间:2016-10-06 08:12:48

标签: spring java-8 spring-integration messaging dsl

在运行应用程序时,流程在routeToRecipients处停止,并且未执行其他组件。 (参见下面代码中的内联注释) 没有发生错误。

但是当我删除routeToRecipients()时,其他组件会执行。

我的整合流程有问题吗?

@MessagingGateway
public interface gateway {
    @Gateway(requestChannel = "request.input")
    void process(List<Msg> test);
}

@Bean(name = PollerMetadata.DEFAULT_POLLER)
public PollerMetadata poller() {
    return Pollers.fixedDelay(1000).get();
}

@Bean
public IntegrationFlow flow() {
    return IntegrationFlows.from("request.input")
            .split()
            .channel(MessageChannels.executor(Executors.newCachedThreadPool()))
            .transform(this.transformer::transform)
            .routeToRecipients(r -> 
                    r.recipient("channel1")
                     .recipient("channel2")
                     .recipient("channel3")
                     .recipient("channel4"))
            .transform(this.transformer::transform2) // <---this is not executed :(
            .handle(new GenericHandler<Msg>() {     // <---this too is not executed
                @Override
                public Object handle(Msg payload, Map<String, Object> headers) {
                    System.out.println("test service activator!");
                    return null;
                }
            })
            .get();
}


@Bean
public IntegrationFlow flow1() {
    return IntegrationFlows.from("channel1")
            .handle(new GenericHandler<Msg>() {
                @Override
                public Object handle(Msg payload, Map<String, Object> headers) {
                    System.out.println("Test route Channel 1")
                    return payload;
                }
            })
            .channel("output")
            .get();
}

@Bean
public IntegrationFlow flow2() {
    return IntegrationFlows.from("channel2")
            .handle(new GenericHandler<Msg>() {
                @Override
                public Object handle(Msg payload, Map<String, Object> headers) {
                    System.out.println("Test route Channel 2")
                    return payload;
                }
            })
            .channel("output")
            .get();
}

@Bean
public IntegrationFlow flow3() {
    return IntegrationFlows.from("channel3")
            .handle(new GenericHandler<Msg>() {
                @Override
                public Object handle(Msg payload, Map<String, Object> headers) {
                    System.out.println("Test route Channel 3")
                    return payload;
                }
            })
            .channel("output")
            .get();
}

    @Bean
public IntegrationFlow flow4() {
    return IntegrationFlows.from("channel4")
            .handle(new GenericHandler<Msg>() {
                @Override
                public Object handle(Msg payload, Map<String, Object> headers) {
                    System.out.println("Test route Channel 4")
                    return payload;
                }
            })
            .channel("output")
            .get();
}

1 个答案:

答案 0 :(得分:0)

路由器没有输出通道 - 它只向收件人发送消息。

您可以在路由器之前放置发布/订阅信道,路由器是一个用户,剩下的信息流是第二个用户。

或者添加channel5并使用该频道启动剩余的流(在新流程中)。