Spring-Integration:如果log是最后一步,“Dispatcher没有订阅者”

时间:2017-05-19 07:44:58

标签: spring spring-integration spring-integration-dsl

我有如下的普通Spring IntegrationFlow,它给了我org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers

这似乎与Flow的最后一步是log步骤有关。如果我删除了log步骤或在该步骤之后进行了另一个身份转换,则不会抛出Dispatcher has no subscribers

我想了解将log作为最后一步的问题是什么。

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        try (ConfigurableApplicationContext ctx = SpringApplication.run(DemoApplication.class, args)) {
            final Gateway gateway = ctx.getBean(Gateway.class);
            final String rs = gateway.send("hello");
            System.out.println(rs);

        }
    }

    @MessagingGateway(defaultRequestChannel = "flow.input")
    public interface Gateway {
        String send(String msg);
    }

    @Bean
    public IntegrationFlow flow() {
        return f -> f
                .transform((String p) -> p + ", world")
                .log(LoggingHandler.Level.INFO, "kljkh"); // throws Dispatcher has no subscribers 
    }
}

以下两个选项有效,但为什么不使用log作为最后一步呢?

@Bean
public IntegrationFlow flow() {
    return f -> f
            .transform((String p) -> p + ", world")
            .log(LoggingHandler.Level.INFO, "kljkh")
            .transform(Function.identity()); // works
}
@Bean
public IntegrationFlow flow() {
    return f -> f
            .transform((String p) -> p + ", world"); // works
}

1 个答案:

答案 0 :(得分:0)

请参阅this answer

日志是窃听。在即将发布的Spring Integration 5.0中,我们允许.log()成为流中的最后一个元素。

解决方法是在最终.channel("nullChannel")之后添加log()