How does rabbitmq heartbeat work
Asked Answered
J

2

17

The native rabbitmq client for java allows to setup heartbeat on connection settings, for example like this:

import com.rabbitmq.client.ConnectionFactory;

...

ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setAutomaticRecoveryEnabled(true);
        connectionFactory.setHost("some://host");
        connectionFactory.setConnectionTimeout(5000);
        connectionFactory.setRequestedHeartbeat(5); // keeps an idle connection alive

What is the rabbitmq client doing with the heartbeat settings? Is it sending a stubbed message to special exchange/queue or what does it else?

Can somebody explain it in details?

Jocose answered 10/11, 2015 at 14:40 Comment(1)
Official RabbitMQ docs has section for hearbeats - rabbitmq.com/heartbeats.htmlNonpayment
S
16

from the RMQ Heartbeat documentation:

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.

This isn't a request to a queue or stubbed message. This is a TCP/IP connection with packets sent across in a specific format for the heartbeat.

If you want the real details, you can read the AMQP 0.9.1 Specification, section 4.2.1 and 4.2.7 with errata on how RabbitMQ corrects for errors in the specification, as well.

Sheltonshelty answered 11/11, 2015 at 1:6 Comment(0)
D
1

The heartbeat timeout value defines after what period of time the peer TCP connection should be considered unreachable (down) by RabbitMQ and client libraries

Diuresis answered 21/10, 2022 at 13:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.