Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any simple way to get the queue length of an ActiveMQ? [closed]

Tags:

java

jms

activemq

How to obtain the queue length (number of unconsumed messages sent to queue) in ActiveMQ, using Java?

like image 461
user705414 Avatar asked Oct 10 '11 15:10

user705414


People also ask

How do I check my ActiveMQ status?

The following will also work to check if ActiveMQ is up and running: try { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(url); // set transport listener so that active MQ start is notified.

How do you clean up ActiveMQ?

However, you can manually delete an unused queue of a stopped instance. Log in as administrator into Apache ActiveMQ. Click Manage ActiveMQ broker, then click Queues. Click Delete in the operations column for the queue that you want to delete.


2 Answers

You have to use JMX, since the Queue interface does not provide such information.

Example of retrieving the size of a specific queue:

// connection
String url = "service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi";
JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(url));
MBeanServerConnection connection = connector.getMBeanServerConnection();
// get queue size
ObjectName nameConsumers = new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=myqueue");
DestinationViewMBean mbView = MBeanServerInvocationHandler.newProxyInstance(connection, nameConsumers, DestinationViewMBean.class, true);
long queueSize = mbView.getQueueSize();

Reference: ActiveMQ JMX, Required MBeans

Example: managing ActiveMQ with JMX APIs

like image 111
Dag Avatar answered Nov 03 '22 18:11

Dag


Like this;

QueueBrowser browser = session.createBrowser(queue);
Enumeration enu = browser.getEnumeration();
List list = new ArrayList();        
  while (enu.hasMoreElements()) {
    TextMessage message = (TextMessage) enu.nextElement();          
    list.add(message.getText());
   }
System.out.println("Size " + list.size());
like image 32
Ratha Avatar answered Nov 03 '22 19:11

Ratha