title: How to check number of pending messages or all messages are processed or not in ActiveMQ using mule flow
body: <p>I have a requirement to stop the ActiveMQ connector if all messages have been processed in the queue. This needs to be done in Mule flow. </p>
  
  <p>As shown below, I have two connectors one for reading and other for writing on vci.staging.queue. I want to check if all messages are processed in the queue then disable the reader connector. </p>
  
  <p>Below piece of script to use client.request from muleContext using queue name and reader or writer connector is always returning ‘null’ for me. </p>
  
  <p>Is there any way to get number of pending messages in a queue or to check if all messages are processed or not so that connector can be disabled? </p>
  
  <pre><code>&lt;jms:activemq-connector name="jmsConnectorStagingQReaderNormal"
                              brokerURL="${mule.activemq.broker.read.normal.url}" 
                              specification="1.1"
                              maxRedelivery="-1"
                              persistentDelivery="true"
                              numberOfConcurrentTransactedReceivers="${mule.activemq.concurrent.receivers}"
                              connectionFactory-ref="connectionFactory"
                              disableTemporaryReplyToDestinations="false"&gt;
          &lt;/jms:activemq-connector&gt;
  
  &lt;jms:activemq-connector name="jmsConnectorStagingQWriter"
                              brokerURL="${mule.activemq.broker.write.url}" 
                              specification="1.1"
                              maxRedelivery="-1"
                              persistentDelivery="true"
                              numberOfConcurrentTransactedReceivers="${mule.activemq.concurrent.receivers}"
                              connectionFactory-ref="connectionFactory"
                              disableTemporaryReplyToDestinations="false"&gt;
          &lt;/jms:activemq-connector&gt;
  
  
  &lt;script:component&gt;
  &lt;script:script engine="groovy"&gt;
          if(muleContext.getRegistry().lookupConnector('jmsConnectorStagingQReaderNormal').isStarted()) {
              if(muleContext.client.request("jms://vci.staging.queue?connector= jmsConnectorStagingQReaderNormal ", 5000) == null) {
                  muleContext.getRegistry().lookupConnector('jmsConnectorStagingQReaderNormal').stop()
               }
          }                               
          return payload
          &lt;/script:script&gt;
  &lt;/script:component&gt;
  </code></pre>