错误“是弹簧集成聚合器 DSL 的单向“MessageHandler”

ber*_*ert 2 spring-integration

我正在尝试使用 DSL 测试一些带有 spring-integration 的东西。到目前为止,这只是一个测试,流程很简单:

  • 创建一些消息
  • 并行处理(记录)它们
  • 聚合它们
  • 记录聚合

除了聚合器,它工作正常:

@Bean
public IntegrationFlow integrationFlow() {
    return IntegrationFlows
            .from(integerMessageSource(), c -> c.poller(Pollers.fixedRate(1, TimeUnit.SECONDS)))
            .channel(MessageChannels.executor(Executors.newCachedThreadPool()))
            .handle((GenericHandler<Integer>) (payload, headers) -> {
                System.out.println("\t delaying message:" + payload + " on thread "
                        + Thread.currentThread().getName());
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    System.err.println(e.getMessage());
                }
                return payload;
            })
            .handle(this::logMessage)
            .aggregate(a ->
                    a.releaseStrategy(g -> g.size()>10)
                     .outputProcessor(g ->
                             g.getMessages()
                                     .stream()
                                     .map(e -> e.getPayload().toString())
                                     .collect(Collectors.joining(",")))

                     )
            .handle(this::logMessage)
            .get();

}
Run Code Online (Sandbox Code Playgroud)

如果我省略了 .aggregate(..), 部分,则示例正在运行。

使用聚合器,我得到以下异常:

Caused by: org.springframework.beans.factory.BeanCreationException: The 'currentComponent' (org.faboo.test.ParallelIntegrationApplication$$Lambda$9/1341404543@6fe1b4fb) is a one-way 'MessageHandler' and it isn't appropriate to configure 'outputChannel'. This is the end of the integration flow.
Run Code Online (Sandbox Code Playgroud)

据我了解,它抱怨聚合器没有输出?

完整来源可以在这里找到:hithub

Gar*_*ell 6

问题是handle()在聚合器之前 - 它没有产生任何结果,所以没有什么可以聚合的......

        .handle(this::logMessage)
        .aggregate(a ->
Run Code Online (Sandbox Code Playgroud)

大概logMessage(Message<?>)有一个void返回类型。

如果要在聚合器之前记录,请使用 a wireTap,或更改logMessage以返回Message<?>记录后。

        .wireTap(sf -> sf.handle(this::logMessage))
Run Code Online (Sandbox Code Playgroud)