[英]Spring Integration: How to consume QueueChannel on-demand as backpressure aware reactive (Flux) pipeline
I have Spring Integration QueueChannel that I want to consume in backpressure aware Flux pipeline.我有 Spring Integration QueueChannel,我想在背压感知 Flux 管道中使用它。
n
Messages from the queue.n
条消息。fun remoteCall(message: Message): Mono<Void>
.fun remoteCall(message: Message): Mono<Void>
。 I don't want to use Poller with scheduler to pull messages from the queue ahead of time.我不想使用 Poller 和调度程序提前从队列中提取消息。
What is the best way to do it in latest Spring Integration + Java/Kotlin DSL, with error recovery etc?在最新的 Spring 集成 + Java/Kotlin DSL 中使用错误恢复等的最佳方法是什么?
See IntegrationReactiveUtils.messageChannelToFlux()
:请参阅
IntegrationReactiveUtils.messageChannelToFlux()
:
/**
* Adapt a provided {@link MessageChannel} into a {@link Flux} source:
* - a {@link org.springframework.integration.channel.FluxMessageChannel}
* is returned as is because it is already a {@link Publisher};
* - a {@link SubscribableChannel} is subscribed with a {@link MessageHandler}
* for the {@link Sinks.Many#tryEmitNext(Object)} which is returned from this method;
* - a {@link PollableChannel} is wrapped into a {@link MessageSource} lambda and reuses
* {@link #messageSourceToFlux(MessageSource)}.
* @param messageChannel the {@link MessageChannel} to adapt.
* @param <T> the expected payload type.
* @return a {@link Flux} which uses a provided {@link MessageChannel} as a source for events to publish.
*/
@SuppressWarnings("unchecked")
public static <T> Flux<Message<T>> messageChannelToFlux(MessageChannel messageChannel) {
Then you can use an IntegrationFlows.from(Publisher)
:然后您可以使用
IntegrationFlows.from(Publisher)
:
/**
* Populate a {@link FluxMessageChannel} to the {@link IntegrationFlowBuilder} chain
* and subscribe it to the provided {@link Publisher}.
* @param publisher the {@link Publisher} to subscribe to.
* @return new {@link IntegrationFlowBuilder}.
*/
public static IntegrationFlowBuilder from(Publisher<? extends Message<?>> publisher) {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.