Error'是Spring-integration聚合器DSL的单向'MessageHandler'

时间:2016-11-21 17:12:49

标签: spring-integration

我正在尝试使用DSL进行弹簧集成测试。到目前为止,这只是一个测试,流程很简单:

  • 制作一些消息
  • 并行处理(登录)
  • 聚合他们
  • 记录聚合

除聚合器外,它运行正常:

@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();

}

如果我遗漏了.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.

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

可以在此处找到完整的来源:hithub

1 个答案:

答案 0 :(得分:3)

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

        .handle(this::logMessage)
        .aggregate(a ->

据推测,logMessage(Message<?>)的回复类型为void

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

        .wireTap(sf -> sf.handle(this::logMessage))