Following is the code to compare two queues of rabbitmq . By using following code you can find out missing queue in other queue .
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.Vector;
import org.apache.commons.codec.binary.Base64;
import org.eclipse.jetty.util.ajax.JSON;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.testng.annotations.Test;
public class GetQueuInfo {
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
String url1="http://queue1:55672/api/definitions";
//Following queue is compared against above queue.
String url2="http://queue1:55672/api/definition";
Vector<String> q1=new Vector<String>();
Vector<String> q2=new Vector<String>();
GetQueuInfo qInfo=new GetQueuInfo();
String response=qInfo.getResponse(url1);
JSONParser parser=new JSONParser();
Object obj=parser.parse(response);
JSONObject json=(JSONObject)obj;
JSONArray jArr=(JSONArray)json.get("queues");
for(int i=0;i<jArr.size();i++)
{
JSONObject jObj=(JSONObject)jArr.get(i);
String name=jObj.get("name").toString();
q1.add(name);
// System.out.println(name);
}
///
response=qInfo.getResponse(url2);
parser=new JSONParser();
obj=parser.parse(response);
json=(JSONObject)obj;
jArr=(JSONArray)json.get("queues");
for(int i=0;i<jArr.size();i++)
{
JSONObject jObj=(JSONObject)jArr.get(i);
String name=jObj.get("name").toString();
q2.add(name);
//System.out.println(name);
}
System.out.println("*****************Missing queues************************");
for(String str:q1)
{
if(!q2.contains(str))
{
System.out.println(str);
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.Vector;
import org.apache.commons.codec.binary.Base64;
import org.eclipse.jetty.util.ajax.JSON;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.testng.annotations.Test;
public class GetQueuInfo {
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
String url1="http://queue1:55672/api/definitions";
//Following queue is compared against above queue.
String url2="http://queue1:55672/api/definition";
Vector<String> q1=new Vector<String>();
Vector<String> q2=new Vector<String>();
GetQueuInfo qInfo=new GetQueuInfo();
String response=qInfo.getResponse(url1);
JSONParser parser=new JSONParser();
Object obj=parser.parse(response);
JSONObject json=(JSONObject)obj;
JSONArray jArr=(JSONArray)json.get("queues");
for(int i=0;i<jArr.size();i++)
{
JSONObject jObj=(JSONObject)jArr.get(i);
String name=jObj.get("name").toString();
q1.add(name);
// System.out.println(name);
}
///
response=qInfo.getResponse(url2);
parser=new JSONParser();
obj=parser.parse(response);
json=(JSONObject)obj;
jArr=(JSONArray)json.get("queues");
for(int i=0;i<jArr.size();i++)
{
JSONObject jObj=(JSONObject)jArr.get(i);
String name=jObj.get("name").toString();
q2.add(name);
//System.out.println(name);
}
System.out.println("*****************Missing queues************************");
for(String str:q1)
{
if(!q2.contains(str))
{
System.out.println(str);
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}