Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does rabbitmq heartbeat work

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?

like image 381
Oleg Majewski Avatar asked Nov 10 '15 14:11

Oleg Majewski


People also ask

What is heartbeat in socket programming?

The heartbeat mechanism monitors the connection between a manager and an agent and automates the cleanup procedure when the connection is lost.

What is heartbeat in Pika?

Pika picks the highest heartbeat value between client and server (and this is the norm in AMQP clients). This means that if you set a heartbeat value lower than 60 seconds, Pika will always pick RabbitMQ's value because it's higher.

Can RabbitMQ lost messages?

Without acknowledgements, message loss is possible during publish and consume operations and only at most once delivery is guaranteed.

Is RabbitMQ at-least-once delivery?

Both Kafka and RabbitMQ offer at-most-once and at-least-once delivery guarantees. Kafka provides exactly-once delivery between producer to the broker using idempotent producers ( enable.


1 Answers

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.

like image 101
Derick Bailey Avatar answered Sep 17 '22 20:09

Derick Bailey