作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Spring AMQP 2.1.6 来使用带有 RabbitListener
的消息返回 Mono<Void>
.例如:
@RabbitListener
public Mono<Void> myListener(MyMessage myMessage) {
Mono<Void> mono = myService.doSomething(myMessage);
return mono;
}
The listener container factory must be configured with AcknowledgeMode.MANUAL so that the consumer thread will not ack the message; instead, the asynchronous completion will ack or nack the message when the async operation completes.
AcknowledgeMode.MANUAL
,但我不清楚“异步完成将在异步操作完成时确认或取消消息”意味着这是由
spring-amqp
处理的。本身或者如果这是我必须做的事情? IE。我是否必须在拨打
myService.doSomething(myMessage)
后确认/取消消息?或者 Spring AMQP 会自动确认它,因为我返回了
Mono
(即使设置了
AcknowledgeMode.MANUAL
)?
RabbitListener
时以非阻塞方式执行此操作的惯用方法是什么? ?
最佳答案
当 Mono 完成时,监听器适配器会处理 ack。
见 AbstractAdaptableMessageListener.asyncSuccess()
和 asyncFailure()
.
编辑
我不是 react 堆的人,但据我所知,我正在完成一个 Mono<Void>
什么都不做,所以on...()
方法永远不会被调用。
您可以使用 channel.basicAck
手动确认交货或 basicReject
...
@RabbitListener(queues = "foo")
public void listen(String in, Channel channel,
@Header(AmqpHeaders.DELIVERY_TAG) long tag) throws IOException {
...
}
关于spring - 如何在 Spring AMQP 中使用响应式(Reactive) RabbitListener Ack/Nack?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56231398/
我是一名优秀的程序员,十分优秀!