0

I am seeing behavior in our stomp.py 7.0 client (listener only) where after some idle time of not receiving messages the ActiveMQ 5.15.9 broker seems to drop the client (i.e. looking at the ActiveMQ management console shows zero consumers). The odd thing is the on_disconnected handler of the client never gets called and we have a health check on the client service that checks the connection is_connected(), however it still returns true.

Based on my understanding/research (please correct if any of this is false) this is due to the broker trying to clean-up resources it perceives as inactive. Also based on my research "heartbeating" can be used to avoid this perception on the broker.

I know how to send the heartbeat header from the client and how to check the response from the server/broker (as far as what it expects) in on_connected but my question is how do I send the actual heartbeat from the client to the server/broker? Do I need to send a message on the queue I am listening to? If so how do I send a "heartbeat message" and not have to adjust message handling code in my listeners? Do I send it without a body? Also does the broker need to be configured to accept heartbeats? and If it is not configured would declaring and sending them from the client still result in the broker disconnecting the client?

Justin Bertram
  • 29,372
  • 4
  • 21
  • 43

1 Answers1

0

Heart-beating is part of STOMP 1.2 so as long as your client supports STOMP 1.2 you should be able to configure heart-beating when the connection is established. Also, if your broker supports STOMP 1.2 it should accept the heart-beat header and adjust its behavior accordingly. You shouldn't have to send your own heart-beats. In the absence of any "normal" STOMP frames the client itself should send an EOL as described in the specification.

If your client doesn't support STOMP 1.2 then you should upgrade to a client that does. The STOMP 1.2 spec was released in October 2012, almost a decade ago now so there's been plenty of time to implement support.

Justin Bertram
  • 29,372
  • 4
  • 21
  • 43
  • Thank you for the fast reply. To clarify, it seems I should send a parameter of heartbeats(5000, 0) if I want to declare that my client would send heartbeats every 5 secs and expects nothing from the broker. Provided my client does not perform any blocking ops longer than that, the broker should not clean-up any resources correct? – user2714417 Feb 20 '22 at 16:14
  • If you send the header `heart-beat:5000,0` to the broker on your `CONNECT` frame then the broker will expect *some* kind of communication every 5 seconds. Even if your application performs a blocking operation the underlying STOMP client implementation should still send the appropriate data to keep the connection alive. That's kind of the whole point of using heart-beating in the first place. – Justin Bertram Feb 21 '22 at 01:49