We have a RabbitMQ Broker (V3.5.7) which is routing messages to a group of servers. When a server instance comes up (perhaps after a restart), I would like get a list of the current bindings for that server, so that I can confirm the bindings. The server is running Java, so that would be the preferred API.
Asked
Active
Viewed 585 times
1 Answers
1
It is an http call, something like that:
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();
}
}
maybe there are more efficient ways, but this is the idea

Gabriele Santomaggio
- 21,656
- 4
- 52
- 52
-
Thank you for the excellent answer! This will work perfectly! – Hephaestus Mar 30 '21 at 03:36
-
Is there a way without doing an http call ? Something that would work with https ? Many thanks ! – R13mus Jan 11 '23 at 13:42
-
You can enable the SSL and execute the call in https: https://www.rabbitmq.com/ssl.html – Gabriele Santomaggio Jan 11 '23 at 17:57