How to find a horneq Queue length
I found those 2 ways
public synchronized int size(){
ClientSession session;
try {
session = sf.createSession(false, false, false);
ClientRequestor requestor = new ClientRequestor(session, "hornetq.management");
ClientMessage m = session.createMessage(false);
ManagementHelper.putAttribute(m, "core.queue." + queueName, "messageCount");
ClientMessage reply = requestor.request(m);
int count = (Integer) ManagementHelper.getResult(reply);
return count;
} catch (Exception e) {
e.printStackTrace();
}
return 0;
}
and
public synchronized int size(){
ClientSession coreSession = null;
int count = 0;
try {
coreSession = sf.createSession(false, false, false);
ClientSession.QueueQuery result;
result = coreSession.queueQuery(new SimpleString(queueName));
count = result.getMessageCount();
} catch (HornetQException e) {
e.printStackTrace();
} finally {
if (coreSession!= null ){
try {
coreSession.close();
} catch (HornetQException e) {
e.printStackTrace();
}
}
}
return count;
}
You have to use the management interface, at the end of this document is an example of retrieving message counts: http://hornetq.sourceforge.net/docs/hornetq-2.0.0.GA/user-manual/en/html/management.html#management.message-counters