简体   繁体   English

不要在 Spring Cloud Stream 的反应式函数中将消息标记为已确认

[英]Don't mark message as acknowledged in reactive Function with Spring Cloud Stream

I am using spring-cloud-stream in version Horsham SR1 with Java 13. I am using Google Pub/Sub as underlying messaging system.我在带有 Java 13 的 Horsham SR1 版本中使用spring-cloud-stream 。我使用 Google Pub/Sub 作为底层消息传递系统。

I have a reactive Function that looks like this:我有一个看起来像这样的反应式Function

@Bean
public Function<Flux<Message>, Mono<Void>> messageConsumer() {
    return messageFlux ->
            messageFlux
                    .flatMap(message -> {
                        // do something
                        return something;
                    })
                    .doOnError(throwable -> log.error("could not process  message", throwable))
                    .then();
}

How can I get Spring to not acknowledge an erroneous message?如何让 Spring确认错误消息? Is it sufficient to throw an exception inside the flatMap method?flatMap方法中抛出异常就足够了吗?

You have to understand that there are pros and cons with each approach and with reactive we have no view into the stream.你必须明白,每种方法都有优点和缺点,而响应式我们无法查看流。 It is completely under your control.它完全在您的控制之下。 In fact one of the main differences is that the above function is only invoked once, where if it was imperative function it would be invoked on each message.事实上,主要区别之一是上述函数只被调用一次,如果它是命令式函数,它将在每条消息上调用。

Basically with reactive user effectively declares the unit of operation as the entire stream (whatever that may mean in he context of your application).基本上,反应式用户有效地将操作单元声明为整个流(无论在您的应用程序上下文中可能意味着什么)。 With imperative the unit of operation is a single Message, hence we can do things like per-message acks, nacks etc.对于命令式,操作单元是单个消息,因此我们可以执行诸如按消息确认、确认等操作。

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

相关问题 没有输出的Spring Cloud Stream反应式监听器 - Spring Cloud Stream Reactive Listener Without Output Spring 云 Stream Function 不会使用 Avro 解串器 - Spring Cloud Stream Function won't use Avro Deserializer 拦截Spring Cloud Stream SubscribableChannel的传入消息 - Intercept incoming message of Spring Cloud Stream SubscribableChannel Spring Cloud Stream 如果使用不同的线程,可轮询消费者 dlq 和 errorChannel 将不起作用 - Spring Cloud Stream pollable consumer dlq and errorChannel don't work if a different thread is being used Spring Cloud Stream不使用Kafka频道绑定器发送消息 - Spring Cloud Stream doesn't use Kafka channel binder to send a message Spring Cloud Stream rabbitmq binder - Spring Cloud 函数错误处理 - Spring cloud stream rabbitmq binder - spring cloud function error handling Spring 云 Stream Function:调用 Z86408593C34AF77FDD160DF932F8B52<t,r> 通过 REST 调用和 output 它到一个 KAFKA 主题</t,r> - Spring Cloud Stream Function : Invoke Function<T,R> via REST call and output it to a KAFKA Topic Spring Cloud Stream Function 支持不起作用 - Spring Cloud Stream Function support does not work Spring Boot Data Rest不支持反应式吗? - Spring Boot Data Rest don't support reactive? 如何使用Spring Cloud Stream应用启动器TCP处理消息 - How to handle message using Spring Cloud Stream app starter TCP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM