未收到RabbitMQ阻塞连接通知

huangapple go评论93阅读模式
英文:

Not Receiving RabbitMQ Blocked Connection Notifications

问题

我尝试在一个AMQP的CachingConnectionFactory上注册一个BlockedListener来处理连接进入/离开Blocked状态的通知,但不幸的是我从未收到任何事件。

在我的Java客户端中,我使用了以下依赖:

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

我的Rabbit服务器使用的是Docker镜像rabbitmq:3-management,对应的是3.8.2Erlang 22.2.4

以下是我用来连接到Rabbit并注册监听器的代码片段:

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);
      }
    });
  }
});

我能够从以下代码行中看到日志条目:

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

但是却看不到从以下代码行中输出的日志:

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

或者

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

我漏掉了什么吗?

英文:

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?

答案1

得分: 1

所以事实证明;上述的代码/设置是 正确 的,然而;Rabbit在你尝试在该连接上发布消息之前不会发送该事件。

英文:

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.

答案2

得分: 0

我正在使用Docker中的RabbitMQ服务器3.7版本,但我发现我的 rabbitmq_amqp1_0 未启用。文档 表示:

> 我们引入了一个AMQP 0-9-1协议扩展,在此扩展中,当连接被阻塞时,代理向客户端发送 connection.blocked 方法,当连接解除阻塞时发送 connection.unblocked

也许你安装了一个 rabbitmq_amqp0_9 插件?我认为协议 1_00_9 是不同的。

root@ffb673602565:/# rabbitmq-plugins list
使用模式 ".*" 列出插件...
已配置:E = 显式启用;e = 隐式启用
 | 状态:* = 在 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
英文:

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

huangapple
  • 本文由 发表于 2020年4月8日 22:18:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/61102919.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定