如何优雅地停止使用@RabbitListener 消费消息

How to gracefully stop consuming messages with @RabbitListener(如何优雅地停止使用@RabbitListener 消费消息)
本文介绍了如何优雅地停止使用@RabbitListener 消费消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

有没有办法优雅地停止 ListenerContainer 及其关联的 Consumers.

Is there a way to gracefully stop a ListenerContainer, and its associated Consumers.

我正在努力实现的目标.

  1. 停止使用消息.
  2. 优雅地停止 ListenerContainer.
  3. 等待长时间运行的消费者,完成后确认.

我可以使用 consumer.stop() 停止 ListenerContainers,但活动的长时间运行的消费者不会成功完成,处理的消息也不会acked 并因此将在 ListenerContainer 恢复后再次处理.

I'm able to stop the ListenerContainers using consumer.stop(), but active long running consumers won't complete successfully, and processed messages won't be acked and will therefore be processed again, once the ListenerContainer has been resumed.

输出

Waiting for workers to finish.
Workers not finished.
Closing channel for unresponsive consumer: Consumer@6d229b1c

消息已处理,但未确认.

The message was processed, but not acked.

我或许可以使用 setForceCloseChannel(false) 实现正常关闭,但是否可以验证取消的消费者是否已完成?SimpleMessageListenerContainer.doShutDown() 有一个本地范围的列表cancelledConsumers".

I might be able to achieve a graceful shutdown using setForceCloseChannel(false), but is it possible to verify if the cancelled consumers has finished? SimpleMessageListenerContainer.doShutDown() has a local scoped List "canceledConsumers".

推荐答案

增加关机超时时间.

请参阅消息侦听器容器配置.

关机超时

当容器关闭时(例如,如果其封闭的 ApplicationContext 已关闭),它会等待处理中的消息,直至达到此限制.默认为五秒.

When a container shuts down (for example, if its enclosing ApplicationContext is closed), it waits for in-flight messages to be processed up to this limit. Defaults to five seconds.

/**
 * The time to wait for workers in milliseconds after the container is stopped. If any
 * workers are active when the shutdown signal comes they will be allowed to finish
 * processing as long as they can finish within this timeout. Defaults
 * to 5 seconds.
 * @param shutdownTimeout the shutdown timeout to set
 */
public void setShutdownTimeout(long shutdownTimeout) {

这篇关于如何优雅地停止使用@RabbitListener 消费消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How to implement RecyclerView with section header depending on category?(如何根据类别实现带有节标题的 RecyclerView?)
How to generate JNI header file in Eclipse(如何在 Eclipse 中生成 JNI 头文件)
Setting a custom HTTP header dynamically with Spring-WS client(使用 Spring-WS 客户端动态设置自定义 HTTP 标头)
Could you technically call the string[] anything in the main method?(从技术上讲,您可以在 main 方法中调用 string[] 吗?)
What is the proper way of setting headers in a URLConnection?(在 URLConnection 中设置标头的正确方法是什么?)
How to overwrite http-header quot;Hostquot; in a HttpURLConnection?(如何覆盖 http-header “主机在 HttpURLConnection 中?)