Search code examples
javajmsactivemq-artemis

How to get a queue from a consumer in JMS?


I have a code that gets a queue from browse, but I can't find a method that gets a queue from a consumer.Is it possible to get a queue from the consumer?

Method for getting a queue from browse:

private void viewMessage() throws NamingException, JMSException {
    Queue queue = (Queue) initialContext.lookup("dynamicQueues/" + "TestQueue");
    queueBrowser = queueSession.createBrowser(queue);
    System.out.println(queueBrowser.getQueue());
}

But I can't find a similar method, but in consumer


Solution

  • The JMS MessageConsumer doesn't have a getQueue() method or any equivalent. However, every JMS Message you receive will have a getJMSDestination() method which will return a Destination which represents where the message came from. Using this information you can deduce the destination to which the consumer is connected.