Search code examples
springspring-cloudspring-cloud-streamspring-rabbit

How to monitor amqp/rabbitMQ connection with Spring?


We have two different AMQP servers (RabbitMQ) and configured one binder for each one.

What is the best way to check the connection status to each of the amqp servers?

One way seems to be to use a AmqpTemplate with CachingConnectionFactory, where one can configure the host. But is there an easier way?

I also tried to go through List<HealthIndicator>. But it contains only one RabbitHealthIndicator when there should be two.

Our config:

spring:
  cloud:
    stream:
      binders:
        binder1:
          type: rabbit
          environment:
            spring:
              rabbitmq:
                host: localhost
                port: 5672
                password: guest
                username: guest
        binder2:
          type: rabbit
          environment:
            spring:
              rabbitmq:
                host: localhost
                port: 56721
                password: guest
                username: guest

Solution

  • So, you have to declare one more RabbitHealthIndicator for the RabbitTemplate on the second ConnectionFactory.

    http://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html#_writing_custom_healthindicators