Is it possible to get a list of queues on a remote broker?

前端 未结 2 1283
自闭症患者
自闭症患者 2021-01-12 17:12

I\'m trying to figure out how to get a list of existing queues on a remote broker.

It looks like I can listen to queues as they are created/destroyed by adding an ad

相关标签:
2条回答
  • 2021-01-12 17:46
        // Create a ConnectionFactory
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
    
    // Create a Connection
    ActiveMQConnection connection = (ActiveMQConnection) connectionFactory.createConnection();
    
    
    //Important point that was missed in the above answer
    connection.start();
    
    DestinationSource ds = connection.getDestinationSource();
    Set<ActiveMQQueue> queues = ds.getQueues();
    
    for(ActiveMQQueue queue : queues){
        try {
            System.out.println(queue.getQueueName());
        } catch (JMSException e) {
            e.printStackTrace();
        }
    }
    
    0 讨论(0)
  • 2021-01-12 18:00

    See this answer: https://stackoverflow.com/a/14021722/3735747

    If you're doing this in Java, there's the DestinationSource class that will help: http://activemq.apache.org/maven/5.7.0/activemq-core/apidocs/org/apache/activemq/advisory/DestinationSource.html

    Create a connection and use the ActiveMQConnection type instead of the JMS Connection type.

    // Create a ConnectionFactory
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
    
    // Create a Connection
    ActiveMQConnection connection = (ActiveMQConnection) connectionFactory.createConnection();
    

    Once you're connected, you can create a DestinationSource object and get the queues:

    DestinationSource ds = connection.getDestinationSource();
    Set<ActiveMQQueue> queues = ds.getQueues();
    
    for(ActiveMQQueue queue : queues){
        try {
            System.out.println(queue.getQueueName());
        } catch (JMSException e) {
            e.printStackTrace();
        }
    }
    
    0 讨论(0)
提交回复
热议问题