activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guillaume Nodet <gno...@apache.org>
Subject Pure JMS management
Date Thu, 18 May 2017 22:23:07 GMT
I'm trying do perform management operation with pure JMS api.
To retrieve the list of queues, I'm currently using the following code:

QueueSession session = ((QueueConnection)
connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue managementQueue = session.createQueue("activemq.management");
QueueRequestor requestor = new QueueRequestor(session, managementQueue);
connection.start();
TextMessage m = session.createTextMessage();
m.setStringProperty("_AMQ_ResourceName", "broker");
m.setStringProperty("_AMQ_OperationName", "getQueueNames");
m.setText("[\"" + routing + "\"]");
Message reply = requestor.request(m);
Class<?> mgmtHelperClass =
connection.getClass().getClassLoader().loadClass("org.apache.activemq.artemis.api.jms.management.JMSManagementHelper");
Method getResultsMethod = mgmtHelperClass.getMethod("getResults",
Message.class);
Object[] results = (Object[]) getResultsMethod.invoke(null, reply);
List<String> names = new ArrayList<>();
for (Object o : (Object[]) (results[0])) {
    names.add(o.toString());
}
return names;


It works, but I think I should not have to use reflection to access the
result message, hence the use of reflection to access the
JMSManagementHelper methods.
It seems to me the reply should be of type TextMessage, but it's currently
untyped, so I can't use TextMessage#getText to retrieve the json result,
and I can't find a way to retrieve it another way.
Do I miss anything ?

-- 
------------------------
Guillaume Nodet

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message