获取 RabbitMQ 的绑定列表

Get list of bindings for RabbitMQ

我们有一个 RabbitMQ Broker (V3.5.7),它将消息路由到一组服务器。当一个服务器实例出现时(可能在重启后),我想获得该服务器当前绑定的列表,以便我可以确认绑定。服务器是 运行 Java,因此首选 API。

这是一个 http 调用,类似于:

 HttpURLConnection connection = null;

        try {
            //Create connection
            URL url = new URL("http://localhost:15672/api/exchanges/%2F/topic_test/bindings/source");
             connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.setRequestProperty("Content-Type",
                    "application/x-www-form-urlencoded");

            connection.setRequestProperty("Content-Language", "en-US");
            String userpass =   "guest:guest";
            String basicAuth = "Basic " + new String(Base64.getEncoder().encode(userpass.getBytes()));
            connection.setRequestProperty ("Authorization", basicAuth);

            connection.setUseCaches(false);
            connection.setDoOutput(true);



            //Get Response
            InputStream is = connection.getInputStream();
            BufferedReader rd = new BufferedReader(new InputStreamReader(is));
            StringBuilder response = new StringBuilder(); // or StringBuffer if Java version 5+
            String line;
            while ((line = rd.readLine()) != null) {
                response.append(line);
                response.append('\r');
            }
            rd.close();

            System.out.println(response.toString());

        } catch (Exception e) {
            e.printStackTrace();

        } finally {
            if (connection != null) {
                connection.disconnect();
            }
        }

也许有更有效的方法,但这就是想法