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.RELEASEcom.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?