This content has been marked as final.
Show 1 reply
-
1. Re: Checking if a queue exists in HornetQ via JMS API
jbertram Sep 3, 2014 1:20 PM (in response to mofarn)To find out if a queue exists or not use the getQueueNames operation on org.hornetq.api.jms.management.JMSServerControl and then loop through the names to see if the one you're looking for exists. It returns a String[].
public boolean queueExists(String queueName) throws Exception { final Queue managementQueue = HornetQJMSClient.createQueue("hornetq.management"); Connection connection = jmsConnectionFactory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); QueueRequestor requestor = new QueueRequestor((QueueSession) session, managementQueue); connection.start(); Message message = session.createMessage(); JMSManagementHelper.putOperationInvocation(m, org.hornetq.api.core.management.ResourceNames.JMS_SERVER, "getQueueNames"); Message reply = requestor.request(message); Object[] results = (Object[])JMSManagementHelper.getResult(reply); for (int i = 0; i < results.length; i++) { System.out.println("Queue name: " + results[i]); if (queueName.equals(((String)results[i]))) return true; } return false; }
There's not a lot of documentation around these individual operations. There's a JIRA open for this already.