Getting queues HornetQ list from Java code

1.2k Views Asked by At

I've tried to get the list of currently active HornetQ queues like this:

ServerLocator locator = HornetQClient.createServerLocatorWithoutHA(new TransportConfiguration(NettyConnectorFactory.class.getName(), getConfigMap()));
ClientSessionFactory factory = locator.createSessionFactory();

ClientSession session = return factory.createSession(true, true, 0);

ClientSession.BindingQuery result = session.bindingQuery(new SimpleString("localhost"));

System.out.println(result.getQueueNames().size());

But it returns 0. Looks like I've performed wrong BindingQuery but I didn't find any examples in documentation.

2

There are 2 best solutions below

1
On

The address here in question is not the IP address.

in HornetQ core queue we have the concept of queues, and each queue (core-queue) will be bound to an address. on this case multiple queues will belong to a single address.

Example:

address: Invoice Queue1: manufacture-invoice Queue2: printing-invoice Queue3: Delivery-invoice

So, you send the messages to the address invoice and each queue will receive the message.

If you want to locate what addresses and queues you have you have to look at management operations, not through the client core-API. The specific API you executed is meant to find the existance of queues on that Address using this concept.

Try playing with JMX Methods to list the queues, or with ManagementServices::getResources(Class classType);

You could also using AS7 management operations or the management console.

0
On

Bit late reply. Hope it helps someone.

ServerLocator locator = HornetQClient.createServerLocatorWithoutHA(new TransportConfiguration(InVMConnectorFactory.class.getName()));
ClientSessionFactory sf = locator.createSessionFactory();
ClientSession session = sf.createSession(false, true, true);
session.start();

ClientRequestor requestor = new ClientRequestor(session, "jms.queue.hornetq.management");
ClientMessage message = session.createMessage(false);
ManagementHelper.putAttribute(message, ResourceNames.CORE_SERVER, "queueNames");
ClientMessage reply = requestor.request(message);
Object queueNames = ManagementHelper.getResult(reply);

pom.xml:

    <dependency>
        <groupId>org.hornetq</groupId>
        <artifactId>hornetq-core-client</artifactId>
        <version>2.3.0.CR1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.hornetq</groupId>
        <artifactId>hornetq-jms-client</artifactId>
        <version>2.3.0.CR1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.hornetq</groupId>
        <artifactId>hornetq-server</artifactId>
        <version>2.3.1.Final</version>
        <scope>provided</scope>
    </dependency>