4

I am required to set up a keepalive endpoint to my web application (tomcat war). The endpoint will be sampled periodically by my WAF to make sure that the app is healthy.

A healthy app means that the application is up and the communication to the RabbitMQ server (version 3.5.3 /spring-rabbit 1.4.5) is up and functional.

I will open some REST API to my WAF that will verify the connection status.
Reading the documentation I am quite lost on how to implement this functionally.
I noticed some functionality that may help, but I am not sure:

  1. Enable automatic recovery and use RecoveryListener and make sure that the last recovery did not fail.
  2. Configure HeartBeat and figure out a way to be notified on “disrupted connections”
  3. Create some Heath Queue and use a plugin like Shovel to echo back the message, if I do not get any response I assume the queue is down
Abhinav
  • 530
  • 8
  • 21
Haim Raman
  • 11,508
  • 6
  • 44
  • 70

1 Answers1

4

You don't need anything special like shovel to implement a health check. Just create a health queue and send/receive to/from it.

If you are using Spring AMQP

rabbitTemplate.send("", "healthQueue", "foo");
String foo = rabbitTemplate.receive("healthQueue");

In addition, you can register a ConnectionListener with Spring AMQP's connection factory and you will be notified when the connection is created/closed.

Spring AMQP has had connection recovery from the beginning so the (relatively new) built-in auto recovery in the rabbitmq client is not used.

If you are not using Spring AMQP use basicPublish and basicGet on a channel to send/receive to/from a health queue.

kryger
  • 12,906
  • 8
  • 44
  • 65
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Isn't it enough just to use `org.springframework.boot.actuate.health.RabbitHealthIndicator` from Spring Boot or at least the same approach in non-boot project? – Maciej Walkowiak May 15 '16 at 20:05
  • Yes, that would work too, to verify the connection is still good. Sending/receiving a message digs one level deeper. – Gary Russell May 15 '16 at 20:16