[英]What is the purpose of RabbitMQ AMQP Java client shutdown handlers?
The RabbitMQ documentation presents how to add a shutdown listener and when the listener is called but I fail to see on what purpose the handler is for. RabbitMQ文档介绍了如何添加关闭侦听器以及何时调用侦听器但我无法查看处理程序的用途。 Seems that all the Java examples (including https://github.com/rabbitmq/rabbitmq-tutorials ) out there ignore shutdown handlers.
似乎所有Java示例(包括https://github.com/rabbitmq/rabbitmq-tutorials )都忽略了关闭处理程序。 In which cases should I prefer shutdown listener over simply catching
ShutdownSignalException
(and IOException
) exception ? 在哪种情况下,我更喜欢关闭侦听器而不是简单地捕获
ShutdownSignalException
(和IOException
)异常?
Another puzzling issue is that where the control flow goes when the handler has finished. 另一个令人费解的问题是当处理程序完成时控制流程的位置。
Potentially relevant related SO questions: 潜在相关的SO相关问题:
Catching IOException can tell you if a connection/channel shutdown occurred as the result of a method invocation, but connections/channels can also be shutdown involuntarily such as if the connection to the server is lost. 捕获IOException可以告诉您是否由于方法调用而发生连接/通道关闭,但是连接/通道也可以被非自愿关闭,例如,如果与服务器的连接丢失。 In this case a ShutdownListener is the only way to learn of the connection/channel closure.
在这种情况下,ShutdownListener是了解连接/通道关闭的唯一方法。
Shutdown listeners are often used to provide connection/channel recovery, though recovering reliably is a challenge of its own. 关闭监听器通常用于提供连接/通道恢复,尽管可靠地恢复是其自身的挑战。 For this, check out Lyra .
为此,请查看Lyra 。
The main use of a ShutdownListener
i've seen is to do automatic reconnection. 我看到
ShutdownListener
的主要用途是自动重新连接。 You listen for a shutdown, and when it happens, try to reconnect. 你监听关机,当它发生时,尝试重新连接。
For example, this is the basis of rabbitmq-ha-client , where it is done in HaConnectionFactory.HaShutdownListener . 例如,这是rabbitmq-ha-client的基础,它在HaConnectionFactory.HaShutdownListener中完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.