[英]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.