官方文檔說:
If a consumer dies (its channel is closed, connection is closed, or TCP connection is lost) without sending an ack, RabbitMQ will understand that a message wasn't processed fully and will re-queue it
即: 如果消費者進程掛掉了(channel關閉, connection關閉,或者tcp連接丟失), 沒有發回確認信息, RMQ將認為消息沒有被處理完, 將重新排隊等待分配。
but how?
答案是:通過心跳來監控。
官方文檔在這里:https://www.rabbitmq.com/heartbeats.html
摘要如下:
=====================================================================
Detecting Dead TCP Connections with Heartbeats
用心跳監控tcp連接是否丟失
Introduction
介紹
Network can fail in many ways, sometimes pretty subtle (e.g. high ratio packet loss). Disrupted TCP connections take a moderately long time (about 11 minutes with default configuration on Linux, for example) to be detected by the operating system. AMQP 0-9-1 offers a heartbeat feature to ensure that the application layer promptly finds out about disrupted connections (and also completely unresponsive peers). Heartbeats also defend against certain network equipment which may terminate "idle" TCP connections.
網絡故障很多種,有時很微妙(比如,丟包比率和高)。 分布式的tcp連接采取適中的時間(比如Linux默認配置大約11分鍾),方便操作系統檢測。AMQP 0-9-1提供heartbeat(心跳)特性來確保應用服務層及時發現已崩潰的連接(和完全無相應的peers)。 心跳機制也能保證進程不被某些網絡設備給殺掉。
Heartbeat Timeout Interval
心跳超時間隔
The heartbeat timeout value defines after what period of time the peer TCP connection should be considered dead by RabbitMQ and client libraries. This value is negotiated between the client and RabbitMQ server at the time of connection. The client must be configured to request heartbeats. In RabbitMQ versions 3.0 and higher, the broker will attempt to negotiate heartbeats by default (although the client can still veto them). The timeout is in seconds, and default value is 60 (580 prior to release 3.5.5).
心跳超時值決定了tcp相互連接的最大時間, 超過了這個時間, 該連接即被RMQ和客戶端視為丟失(dead)。 這個值在客戶端和服務器建立連接的時候協商確定。客戶端需配才能發心跳包。 RMQ3.0及以上版本, RMQ將試着將beatheart協調為默認值(客戶端可以否決這個值)。 超時時間單位為秒,默認值為60( 3.5.5發布版之前是580)。
Heartbeat frames are sent about every timeout / 2 seconds. After two missed heartbeats, the peer is considered to be unreachable. Different clients manifest this differently but the TCP connection will be closed. When a client detects that RabbitMQ node is unreachable due to a heartbeat, it needs to re-connect.
心跳包每半個超時時間發送一次。 丟失了兩個心跳包, 連接被認為不可抵達。 不同的客戶端有不同的提示, 但tcp連接都會被關閉。 當客戶端檢測到RMQ節點不可抵達(根據心跳判定), 它需要重新連接(到服務器)。
Heartbeats can be disabled by setting the timeout interval to 0.
心跳機制可以被禁用:設定超時間隔為0。
轉載請注明本文源頭:http://www.cnblogs.com/Tommy-Yu/p/5775852.html
謝謝!