Hi
I had a hard time following the management api documentation and doing mangement operations listed here: http://docs.jboss.org/hornetq/2.2.5.Final/user-manual/en/html/management.html
All examples that I found on the forums were showing how to connect using JMX; which I didn't really want to explore. I just needed a simple pure java object that will connect to hornetQ and do some managment operation. It took me a while to figure this out; so I decided to share this example in case anyone else needs to do the same.
My use case is as follows: hornetQ server running on same host
| Map<String, Object> connectionParams = new HashMap<String,Object>(); |
| connectionParams.put(org.hornetq.core.remoting.impl.netty.TransportConstants.HOST_PROP_NAME, "myhostname"); |
| ServerLocator serverLocator = HornetQClient.createServerLocatorWithoutHA(new TransportConfiguration(NettyConnectorFactory.class.getName(), connectionParams)); |
| ClientSessionFactory sf = serverLocator.createSessionFactory(); |
|
|
| ClientSession session = sf.createSession(); |
| session.start(); |
|
|
| ClientRequestor requestor = new ClientRequestor(session, "jms.queue.hornetq.management"); |
| ClientMessage message = session.createMessage(false); |
|
|
|
|
| // calling this method http://docs.jboss.org/hornetq/2.2.5.Final/api/org/hornetq/api/core/management/QueueControl.html#getAddress%28%29 |
| ManagementHelper.putOperationInvocation(message, ResourceNames.CORE_QUEUE + "queue1", "getAddress"); |
| ClientMessage reply = requestor.request(message); |
| String addr = (String) ManagementHelper.getResult(reply); |
|
|
| System.out.println("got reply: " + addr); |
|
|