Not Receiving RabbitMQ Blocked Connection Notifications

Viewed 447

I'm attempting to register a BlockedListener on an AMQP CachingConnectionFactory to process notifications of connections entering/leaving a Blocked state. Unfortunately I'm never receiving any events.

In my Java client I'm using:

  • org.springframework.amqp:spring-rabbit:jar:2.1.11.RELEASE
  • com.rabbitmq:amqp-client:jar:5.4.3

My Rabbit server is using the docker image rabbitmq:3-management which maps to 3.8.2 and Erlang 22.2.4

This is the code snippet I'm using to connect to rabbit and register the listener.

com.rabbitmq.client.ConnectionFactory rmqConnectionFactory = new com.rabbitmq.client.ConnectionFactory();
rmqConnectionFactory.useNio();
rmqConnectionFactory.setHost(rabbitmqHost);
rmqConnectionFactory.setUsername(rabbitmqUsername);
rmqConnectionFactory.setPassword(rabbitmqPassword);
rmqConnectionFactory.setPort(rabbitmqPort);
rmqConnectionFactory.setVirtualHost(rabbitmqVirtualHost);

CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(rmqConnectionFactory);
cachingConnectionFactory.addConnectionListener(new ConnectionListener() {
  @Override
  public void onCreate(Connection connection) {
    log.info("New connection: {}", connection);
    connection.getDelegate().addBlockedListener(new BlockedListener() {
      @Override
      public void handleBlocked(String s) {
        log.warn("Connection {} entered a blocked state with message {}", connection, s);
      }
      @Override
      public void handleUnblocked() {
        log.info("Connection {} left a blocked state", connection);
      }
    });
  }
});

I get log entries from

log.info("New connection: {}", connection);

But not from

log.warn("Connection {} entered a blocked state with message {}", connection, s);

or

log.info("Connection {} left a blocked state", connection);

What am I missing?

2 Answers

So it turns out; the above code/setup is correct however; Rabbit doesn't send the event until you attempt to publish a message on that connection.

I'm using RabbitMQ server 3.7 in docker, but I can see that my rabbitmq_amqp1_0 is not enabled. The documentation says:

We have introduced an AMQP 0-9-1 protocol extension in which the broker sends to the client a connection.blocked method when the connection gets blocked, and connection.unblocked when it is unblocked.

Perhaps you install a rabbitmq_amqp0_9 plugin? I think the protocols 1_0 and 0_9 are different.

root@ffb673602565:/# rabbitmq-plugins list
Listing plugins with pattern ".*" ...
 Configured: E = explicitly enabled; e = implicitly enabled
 | Status: * = running on rabbit@ffb673602565
 |/
[  ] rabbitmq_amqp1_0                  3.7.11
[  ] rabbitmq_auth_backend_cache       3.7.11
[  ] rabbitmq_auth_backend_http        3.7.11
[  ] rabbitmq_auth_backend_ldap        3.7.11
[  ] rabbitmq_auth_mechanism_ssl       3.7.11
[  ] rabbitmq_consistent_hash_exchange 3.7.11
[  ] rabbitmq_event_exchange           3.7.11
[  ] rabbitmq_federation               3.7.11
[  ] rabbitmq_federation_management    3.7.11
[  ] rabbitmq_jms_topic_exchange       3.7.11
[E*] rabbitmq_management               3.7.11
[e*] rabbitmq_management_agent         3.7.11
[  ] rabbitmq_mqtt                     3.7.11
[  ] rabbitmq_peer_discovery_aws       3.7.11
[  ] rabbitmq_peer_discovery_common    3.7.11
[  ] rabbitmq_peer_discovery_consul    3.7.11
[  ] rabbitmq_peer_discovery_etcd      3.7.11
[  ] rabbitmq_peer_discovery_k8s       3.7.11
[  ] rabbitmq_random_exchange          3.7.11
[  ] rabbitmq_recent_history_exchange  3.7.11
[  ] rabbitmq_sharding                 3.7.11
[  ] rabbitmq_shovel                   3.7.11
[  ] rabbitmq_shovel_management        3.7.11
[  ] rabbitmq_stomp                    3.7.11
[  ] rabbitmq_top                      3.7.11
[  ] rabbitmq_tracing                  3.7.11
[  ] rabbitmq_trust_store              3.7.11
[e*] rabbitmq_web_dispatch             3.7.11
[  ] rabbitmq_web_mqtt                 3.7.11
[  ] rabbitmq_web_mqtt_examples        3.7.11
[  ] rabbitmq_web_stomp                3.7.11
[  ] rabbitmq_web_stomp_examples       3.7.11
Related