Listing queues and topics in ActiveMQ

This will provide the list of queues and topics managed by an ActiveMQ broker…

import javax.jms.*;
import java.util.*;
import org.apache.activemq.*;
import org.apache.activemq.command.*;
import org.apache.activemq.advisory.*;

public class GetDestinations {
  private static String url = ActiveMQConnection.DEFAULT_BROKER_URL;
  public static void main(String[] args) throws Exception {
    ActiveMQConnectionFactory connectionFactory=new ActiveMQConnectionFactory("admin", "password", 
    ActiveMQConnection connection = (ActiveMQConnection)connectionFactory.createConnection();
    Session session = connection.createSession(true,  Session.AUTO_ACKNOWLEDGE);
    DestinationSource dest = connection.getDestinationSource();
    Set amqt = dest.getTopics();
    Iterator queues2 = amqt.iterator();
    while (queues2.hasNext()) {
      ActiveMQTopic queue3 =;
      System.out.println(new Date() + "\t" + "Topic: " + queue3.getPhysicalName());
    Set amqs = dest.getQueues();
    Iterator queues = amqs.iterator();
    while (queues.hasNext()) {
      ActiveMQQueue queue2 =;
      System.out.println("Queue: " + queue2.getPhysicalName());

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.