16

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?

Oleg Majewski
  • 989
  • 1
  • 9
  • 13

2 Answers2

14

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.

Derick Bailey
  • 72,004
  • 22
  • 206
  • 219
0

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

Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197