RabbitMQ流控制不起作用(Java客户端)

时间:2017-05-30 21:45:45

标签: java rabbitmq

我按如下方式构建RabbitMQ(RabbitMQ 3.6.5,Erlang R16B03)连接:

ConnectionFactory factory = new ConnectionFactory();
factory.setHost(App.rabbitMQServer);
factory.setVirtualHost(App.rabbitVirtualHost);
factory.setRequestedHeartbeat(5);
factory.setConnectionTimeout(5000);
factory.setAutomaticRecoveryEnabled(true);        
factory.setNetworkRecoveryInterval(5000);

Map<String, Object> clientProperties = new HashMap<>();
Map<String, Object> capabilities = new HashMap<>();
capabilities.put("connection.blocked", true);
clientProperties.put("capabilities", capabilities);
factory.setClientProperties(clientProperties);

_connection = factory.newConnection();

_channel = _connection.createChannel();

_connection.addBlockedListener(new BlockedListener() {
    public void handleBlocked(String reason) throws IOException {               
        connectionIsBlocked = true;
        log.warn("RabbitMQ connection blocked");
    }

    public void handleUnblocked() throws IOException {
        connectionIsBlocked = false;
        log.warn("RabbitMQ connection unblocked");
    }
});        

管理Web控制台中的连接看起来没问题 - 但是存在功能但是从不调用BlockedListener方法。我错过了什么?

顺便说一下,我有另一个用Go编写的进程,它也从不调用它的流监听器......

flow := ch.NotifyFlow(make(chan bool))
go func() {
    for f := range flow {
        shouldFailoverToSQS = f
        log.Infof("Flow status changed")
    }
}()

1 个答案:

答案 0 :(得分:0)

我混淆了BlockedListener和FlowListener(不推荐使用)。