如何在rabbitmq中查找绑定到特定交换的队列数量?

Dhi*_*mar 5 java rabbitmq

我正在尝试用 java 实现 Rabbitmq 教程中指定的发布/订阅模型。那里提供的示例效果很好。现在我想对其进行修改,限制访问 Exchange 的客户端数量。

当我查看它时,我可以找到一个命令“rabbitmqctl list_bindings”来列出有界队列,这是手动输入的。有没有办法以编程方式做到这一点?或者我们是否有任何交换函数可以返回绑定到交换器的队列数?

我找不到任何内容,请帮助我,我们将不胜感激。

Gab*_*ele 3

您可以使用管理UI HTTP API,在这里您可以找到所有API

你可以使用API/api/exchanges/{vhost}/{exchange_name}/bindings/source

例如:

http://localhost:15672/api/exchanges/%2F/Topic_test/bindings/source
Run Code Online (Sandbox Code Playgroud)

你会得到一个 json 结果,类似于:


[

    {
        "source": "Topic_test",
        "vhost": "/",
        "destination": "test_0",
        "destination_type": "queue",
        "routing_key": "",
        "arguments": { },
        "properties_key": "~"
    },
    {
        "source": "Topic_test",
        "vhost": "/",
        "destination": "test_1",
        "destination_type": "queue",
        "routing_key": "",
        "arguments": { },
        "properties_key": "~"
    },
    {
        "source": "Topic_test",
        "vhost": "/",
        "destination": "test_2",
        "destination_type": "queue",
        "routing_key": "",
        "arguments": { },
        "properties_key": "~"
    }
]
Run Code Online (Sandbox Code Playgroud)