Skip to content

Instantly share code, notes, and snippets.

@sachin-handiekar
Created November 18, 2014 16:52
Show Gist options
  • Save sachin-handiekar/6afbcdc28dbd3ead0626 to your computer and use it in GitHub Desktop.
Save sachin-handiekar/6afbcdc28dbd3ead0626 to your computer and use it in GitHub Desktop.
Get ActiveMQ Queue Size using MBean (Spring JMX) - QueueSizeCounter.java
package com.sample;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import org.apache.log4j.Logger;
public class QueueSizeCounter {
private MBeanServerConnection mBeanServerConnection;
private Logger logger = Logger.getLogger(QueueSizeCounter.class);
public Long getQueueSize(String queueName) {
Long queueSize = null;
try {
ObjectName objectNameRequest = new ObjectName(
"org.apache.activemq:BrokerName=localhost,Type=Queue,Destination=" + queueName);
queueSize = (Long) mBeanServerConnection.getAttribute(objectNameRequest, "QueueSize");
return queueSize;
}
catch (Exception e) {
logger.error(e.getMessage());
}
return queueSize;
}
public void setmBeanServerConnection(MBeanServerConnection mBeanServerConnection) {
this.mBeanServerConnection = mBeanServerConnection;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment