28.4. Using Management Via JMS

Using JMS messages to manage HornetQ is very similar to using core API.
An important difference is that JMS requires a JMS queue to send the messages to (instead of an address for the core API).
The management queue is a special queue and needs to be instantiated directly by the client:
   Queue managementQueue = HornetQJMSClient.createQueue("hornetq.management");
All the other steps are the same as for the Core API but they use JMS API instead:
  1. Create a QueueRequestor to send messages to the management address and receive replies.
  2. Create a Message.
  3. Use the helper class org.hornetq.api.jms.management.JMSManagementHelper to fill the message with the management properties.
  4. Send the message using the QueueRequestor.
  5. Use the helper class org.hornetq.api.jms.management.JMSManagementHelper to retrieve the operation result from the management reply.
For example, to know the number of messages in the JMS queue exampleQueue:
   Queue managementQueue = HornetQJMSClient.createQueue("hornetq.management");   
   
   QueueSession session = ...      
   QueueRequestor requestor = new QueueRequestor(session, managementQueue);
   connection.start();
   Message message = session.createMessage();
   JMSManagementHelper.putAttribute(message, "jms.queue.exampleQueue", "messageCount");
   Message reply = requestor.request(message);
   int count = (Integer)JMSManagementHelper.getResult(reply);
   System.out.println("There are " + count + " messages in exampleQueue");

28.4.1. Configuring JMS Management

Whether JMS or the core API is used for management, the configuration steps are the same (see Section 28.3.1, “Configuring Core Management”).