// Create connection
Connection con = new Connection();
con.connect("localhost", 5672, "test", "guest", "guest",false);
// Create session
Session session = con.createSession(0);
// Create an instance of the listener
TopicListener listener = new TopicListener();
session.setSessionListener(listener);
listener.prepareQueue(session,"usa", "usa.#");
listener.prepareQueue(session,"europe", "europe.#");
listener.prepareQueue(session,"news", "#.news");
listener.prepareQueue(session,"weather", "#.weather");
// confirm completion
session.sync();
System.out.println("Waiting 100 seconds for messages");
Thread.sleep(100*1000);
System.out.println("Shutting down listeners");
listener.cancelSubscription(session,"usa");
listener.cancelSubscription(session,"europe");
listener.cancelSubscription(session,"news");
listener.cancelSubscription(session,"weather");
//cleanup
session.close();
con.close();
}