RabbitMQ-C - How to enable heartbeats for my C client connections.

2,665 views
Skip to first unread message

Rodrigo Pimenta Carvalho

unread,
Sep 16, 2014, 3:20:40 PM9/16/14
to rabbitm...@googlegroups.com
Hi RabbitMQ-C users.

How to enable heartbeats for my client connections, say set the heartbeat timeout
to 10 seconds? It is possible to do that by means of the library RabbitMQ-C?

It is necessary to my project, because if my client is suddenly interrupted, let's say due to a power supply problem, the broker must notice that the client is no more there and destroy the respective connection and related channels.

Any hint will be very helpful!
Thanks a lot!

Regards.

RODRIGO PIMENTA CARVALHO
Inatel Competence Center
Software
Ph: +55 35 3471 9979 (Brasil)

Alan Antonuk

unread,
Sep 16, 2014, 5:56:10 PM9/16/14
to Rodrigo Pimenta Carvalho, rabbitm...@googlegroups.com
You enable them my passing a value greater than 0 for the heartbeat parameter of amqp_login() or amqp_login_with_parameters(). See: https://github.com/alanxz/rabbitmq-c/blob/master/librabbitmq/amqp.h#L1696

Note that the heartbeats are only serviced while in a blocking call to the library (e.g., amqp_consume_message()).

-Alan

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send an email to rabbitm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

l rus

unread,
Oct 16, 2014, 11:12:47 PM10/16/14
to rabbitm...@googlegroups.com, pim...@inatel.br
 
amqp_login(_connection, vHost, 0, 131072, heartbeatInterval, AMQP_SASL_METHOD_PLAIN,
                userName.c_str(), password.c_str()), "AMQP Login failed", die)
 
 
While heartbeatInterval is 70, I keep I receiving heartbeat update delivered thru the server
via blocking amqp_consume_message()  every 60 seconds.
 
 
Not sure what I am missing here..

Michael Klishin

unread,
Oct 17, 2014, 2:29:39 AM10/17/14
to rabbitm...@googlegroups.com, l rus, pim...@inatel.br


On 17 October 2014 at 07:12:52, l rus (zxto...@gmail.com) wrote:
> While heartbeatInterval is 70, I keep I receiving heartbeat
> update delivered thru the server
> via blocking amqp_consume_message() every 60 seconds.

Should be about 34-35 . It's not an interval, it's a heartbeat timeout,
which is 2 missed heartbeat frames in a row.
--
MK

Staff Software Engineer, Pivotal/RabbitMQ

Alan Antonuk

unread,
Oct 17, 2014, 12:44:42 PM10/17/14
to l rus, rabbitm...@googlegroups.com, Rodrigo Pimenta Carvalho
I'm confused, what is your question?

To post to this group, send email to rabbitm...@googlegroups.com.

Alan Antonuk

unread,
Oct 17, 2014, 12:47:58 PM10/17/14
to Michael Klishin, rabbitm...@googlegroups.com, l rus, Rodrigo Pimenta Carvalho
On Thu, Oct 16, 2014 at 11:29 PM, Michael Klishin <mkli...@pivotal.io> wrote:


On 17 October 2014 at 07:12:52, l rus (zxto...@gmail.com) wrote:
> While heartbeatInterval is 70, I keep I receiving heartbeat
> update delivered thru the server
> via blocking amqp_consume_message() every 60 seconds.

Should be about 34-35 . It's not an interval, it's a heartbeat timeout,
which is 2 missed heartbeat frames in a row.

In rabbitmq-c the parameter passed into amqp_login specifies the time between heartbeat frames.  The library will assume the connection is broken if it doesn't see communication from the server in 2x this number. Assuming no other communication is happening, the library will attempt to send a heartbeat at each interval.
 
--
MK

Staff Software Engineer, Pivotal/RabbitMQ
--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.

l rus

unread,
Oct 17, 2014, 4:04:48 PM10/17/14
to rabbitm...@googlegroups.com, zxto...@gmail.com, pim...@inatel.br


Since the server sends heartbeats every 60 seconds,
if i set this value to 29 secs with amqp_login (for testing),
AMQP_STATUS_HEARTBEAT_TIMEOUT should be generated.
However, none observed..

Michael Klishin

unread,
Oct 17, 2014, 4:09:46 PM10/17/14
to rabbitm...@googlegroups.com, l rus, pim...@inatel.br
 On 18 October 2014 at 00:04:54, l rus (zxto...@gmail.com) wrote:
> Since the server sends heartbeats every 60 seconds,
> if i set this value to 29 secs with amqp_login (for testing),
> AMQP_STATUS_HEARTBEAT_TIMEOUT should be generated.
> However, none observed..

If you set the timeout interval to 29 seconds, both peers should
(and RabbitMQ server will) send heartbeat frames roughly every
14 seconds.

Timeout occurs when 2 heartbeat frames were missed by the peer.

l rus

unread,
Oct 20, 2014, 12:04:56 PM10/20/14
to rabbitm...@googlegroups.com, zxto...@gmail.com, pim...@inatel.br


> both peers should send heartbeats

   which two peers? heartbeats are generated only by rabbitmq server. right?

   As client gets heartbeats from the server every 60 seconds,
   i should set for the heartbeat timeout of 120 seconds or more with amqp_login().

   But just to test out heartbeat timeout by AMQP client, as i do not have control over
   server config, i can set the value to 28-29 and having not received server heartbeat in
   59 seconds (equivalent to two missed heatbeats), the client should get
   AMQP_STATUS_HEARTBEAT_TIMEOUT.

   However, the client did not get errors while doing amqp_consume_message().

Michael Klishin

unread,
Oct 20, 2014, 12:49:51 PM10/20/14
to rabbitm...@googlegroups.com, l rus, pim...@inatel.br
 On 20 October 2014 at 20:05:02, l rus (zxto...@gmail.com) wrote:
> which two peers? heartbeats are generated only by rabbitmq
> server. right?

Wrong. Both client and server must send heartbeats if they are enabled.

> As client gets heartbeats from the server every 60 seconds,
> i should set for the heartbeat timeout of 120 seconds or more with
> amqp_login().

Correct. 2 missed heartbeats are considered to be a timeout. Note that the clients
may use a value slightly lower than 1/2 of the timeout to account for network latency.

TT

unread,
Apr 17, 2015, 10:17:03 AM4/17/15
to rabbitm...@googlegroups.com, pim...@inatel.br, zxto...@gmail.com
Slightly related question, does the c library now have an event loop to handle heartbeats? Found this thread from 2013 back then it didn't http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/2013-March/025867.html


Alan Antonuk

unread,
Apr 17, 2015, 6:39:12 PM4/17/15
to TT, rabbitm...@googlegroups.com, Rodrigo Pimenta Carvalho, l rus
rabbitmq-c does not currently have an event loop.  Support for heartbeats is still considered partial: they are correctly serviced doing a blocking read from the socket, and PR#256 will land support for heartbeat servicing when in a blocking write (publish).

I have started work on allowing rabbitmq-c to integrate with an event loop, which will add full support for async events to rabbitmq-c, including heartbeat support. This will likely be a bring your own event-loop, as there are quite a number users with different event-loop needs, but the plan is to provide something that can be used out of the box.  Currently there is no timeline for when this will be ready.

-Alan

On Fri, Apr 17, 2015 at 7:17 AM, TT <tum...@gmail.com> wrote:
Slightly related question, does the c library now have an event loop to handle heartbeats? Found this thread from 2013 back then it didn't http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/2013-March/025867.html


--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages