如何使用 "Mono" 处理程序确认所有成功的消息?

How to acknowledge all successful messages with "Mono" handler?

我正在使用 spring amqp 并使用异步 return 类型,例如 Mono。我的一位经纪人:

    @RabbitHandler
    public Mono<Response<PopularityReport>> popularityReport(PopularityReportCommand command) {
        return Mono.just(foo);
    }

当我使用这种方法时,我收到下一个警告:

[ntContainer#0-1] .a.r.l.a.MessagingMessageListenerAdapter : Container AcknowledgeMode must be MANUAL for a Mono<?> return type; otherwise the container will ack the message immediately

我可以使用下一个 进行手动致谢。但是我有一百个处理程序,因此,这种方法对我来说似乎很不方便(我需要更改所有处理程序)。

我只想在成功执行后才确认所有消息。 我如何在不更改旧代码的情况下在一个地方为我的所有处理程序编写全局策略?

您不需要手动确认此类消息;当 Mono 完成时,框架会处理它。

该警告只是告诉您容器未针对此 return 类型正确配置。