Spring integration 发布-订阅流后从入站适配器移动文件

Spring integration 发布-订阅流后从入站适配器移动文件,spring-integration,spring-integration-dsl,Spring Integration,Spring Integration Dsl,我正在尝试实现以下流程: 1) 从入站适配器读取文件 2) 使用具有应用顺序的发布-订阅通道将它们发送到不同的流 3) 在所有订户流就绪后移动文件 这是主流 return IntegrationFlows .from(Files.inboundAdapter(inboundOutDirectory) .regexFilter(pattern) .useWat

我正在尝试实现以下流程: 1) 从入站适配器读取文件 2) 使用具有应用顺序的发布-订阅通道将它们发送到不同的流 3) 在所有订户流就绪后移动文件

这是主流

return IntegrationFlows
                .from(Files.inboundAdapter(inboundOutDirectory)
                           .regexFilter(pattern)
                           .useWatchService(true)
                           .watchEvents(FileReadingMessageSource.WatchEventType.CREATE),
                        e -> e.poller(Pollers.fixedDelay(period)
                                             .taskExecutor(Executors.newFixedThreadPool(poolSize))
                                             .maxMessagesPerPoll(maxMessagesPerPoll)))
                .publishSubscribeChannel(s -> s
                        .applySequence(true)
                        .subscribe(f -> f
                                .transform(Files.toStringTransformer())
                                .<String>handle((p, h) -> {
                                       return "something"
                                    }
                                })                                
                                .channel("consolidateFlow.input"))
                        .subscribe(f -> f
                                .transform(Files.toStringTransformer())
                                .handle(Http.outboundGateway(testUri)
                                            .httpMethod(HttpMethod.GET)
                                            .uriVariable("text", "payload")                                            .expectedResponseType(String.class))
                                .<String>handle((p, h) -> {
                                    return "something";
                                })
                                .channel("consolidateFlow.input")))
                .get();
结果是

原因:org.springframework.messaging.core.DestinationResolutionException:没有可用的输出通道或replyChannel标头

如果我这样做,整合/聚合流将根本无法实现

.handle(Files.outboundAdapter(this.inboundProcessedDirectory))
你知道我该怎么解决吗?目前,我正在通过读取头中的原始文件名来移动聚合后的文件,但这似乎不是正确的解决方案。 我还考虑使用成功逻辑将spec/advice应用到入站适配器以移动文件,但不确定这是否是正确的方法

EDIT1 根据Artem的建议,我已将另一个订阅者添加到发布订阅中,如下所示:

...
.channel("consolidateNlpFlow.input"))
                        .subscribe(f -> f
                                .handle(Files.outboundAdapter(this.inboundProcessedDirectory).deleteSourceFiles(true))
...
文件已正确移动,但根本没有执行consolidateFlow。有什么想法吗?
我还尝试将通道添加到新的流
.channel(“consolidateNlpFlow.input”)
,但它没有改变行为。

您的问题是
consolidateFlow
无法将结果返回到主流中。只是因为有任何像网关一样的东西。你在那里做了一个显式的
.channel(“consolidateFlow.input”)
,这意味着没有回头路了。 这就是你到目前为止遇到的问题

关于可能的解决办法


根据您的配置,
publishSubscribeChannel
中的两个订阅服务器都在同一线程上逐个执行。因此,您可以很容易地使用
文件.outboundAdapter()
删除源文件(true)
再添加一个订户。这个将在现有订阅者之后被调用。

Perfect,我不知道发布-订阅是按顺序执行的。你能看一下EDIT1吗?嗨@artem bilan,有机会看一下EDIT1吗?最后一次尝试;)你能不能帮我看看EDIT1?你为什么需要这个聚合?那是什么
.channel(“consolidateNlpFlow.input”)
?它在主流中看起来如何?请考虑使用散列收集为您的用例,如果你不能生活没有聚集后分发。您可以将
文件.outboundAdapter(此.inboundProcessedDirectory)
添加到
consolidateFlow
中。没错,您确实需要从头文件中提取一个文件,但这也应该是一个解决方案。现在我在你的配置中迷失了方向,我无法连接这些部分。谢谢你的理解
.handle(Files.outboundAdapter(this.inboundProcessedDirectory))
...
.channel("consolidateNlpFlow.input"))
                        .subscribe(f -> f
                                .handle(Files.outboundAdapter(this.inboundProcessedDirectory).deleteSourceFiles(true))
...