繁体   English   中英

如何访问 Spring 集成流程中间的通量?

[英]How to access a flux in the middle of a Spring Integration flow?

我尝试访问 Spring Integration 中的 flux object,而不将流声明拆分为两个函数。 我想知道如何执行以下操作:

@Bean
public IntegrationFlow mainFlow() {
   return IntegrationFlows.from(somePublisher)
      // Access publisher here to perform something like:
      .handle(flux -> flux.buffer(Duration.ofMillis(200))
      .handle(writeToS3)
      .get();
}

我不介意将我在评论中谈论的通量操作移动到另一个 class(可能是某种网关),但显然对我来说非常重要的是从同一个mainFlow function 开始和流动,因此,理解我在我的应用程序中所做的事情将非常清晰易读。 我看到了带有 Monos 的网关的文档,但是示例代码甚至是不可能的(他们谈论的 Flux 不在 function 中,作为初学者,我很难理解那里发生了什么)。

IntegrationFlows.from(somePublisher)为提供的Publisher启动一个 ractive stream。 流程的 rest 是针对源Publisher中的每个事件完成的。 因此,只有当来自源的事件是Flux时,您的.handle(flux ->)才会起作用。

如果你想为源Publisher者和 go 应用buffer() ,那么考虑使用reactive()定制器: https://docs.spring.io/spring-integration/docs/current/reference/html/reactive -streams.html#fluxmessagechannel-and-reactivestreamsconsumer

因此,我将使用以下 handle() 而不是handle()

.bridge(e -> e.reactive(flux -> flux.buffer(Duration.ofMillis(200)))

下一个handle(writeToS3)将针对缓冲的List结果执行,因此请注意您在writeToS3中所做和期望的事情。

Artem 的回答很好而且正确,但我真正想要的是:

.fluxTransform(messageFlux -> messageFlux.buffer(Duration.ofMillis(200)))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM