Announcement Announcement Module
No announcement yet.
Get size of a queue with Control Bus Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Get size of a queue with Control Bus


    is there a possibility to get the size of a queue with the control-bus of Spring Integration?

    I wrote a class to start and stop some endpoints with die control-bus. Now I want to get the size of some queues.

    I tried it with this statement

    send(new GenericMessage<String>("@readEventChannel.getQueueSize()"));
    but it doesn't work.

    Caused by: org.springframework.expression.EvaluationException : The method 'getQueueSize' is not supported by this command processor. If using the Control Bus, consider adding @ManagedOperation or @ManagedAttribute.

    When I inject the channel bean to the class, the channel ist not a instance of QueueChannel.

    <si:channel id="readEventChannel" >
    	<si:queue  />
    <bean id="applicationMonitor" class="com.example.ApplicationMonitor">
    	<property name="controlChannel" ref="controlChannel" />
    	<property name="controlOutputChannel" ref="controlOutputChannel" />
    	 <property name="queueList">
    			<ref bean="readEventChannel" />
    Is there another solution?

  • #2
    The Exception makes sense as the method needs to be annotated with @ManagedOperation or @ManagedAttribute if we want to use control bus to invoke it.

    What you can do is, have a class, something like below

    public class ApplicationControlPanel implements BeanFactoryAware {
    	private BeanFactory factory;
    	public int getQueueSize(String queueName) {
    		try {
    			QueueChannel channel = factory.getBean(queueName, QueueChannel.class);		
    			return channel.getQueueSize();
    		} catch (NoSuchBeanDefinitionException nb) {
    			return -1;
    	public void setBeanFactory(BeanFactory factory) throws BeansException {
    		this.factory = factory;		
    Here you can use control bus to invoke this getQueueSize method of this class, all you need to pass is the
    id of the queue channel you want to check. If one is found, you'll get the value else -1.


    • #3
      This is not currently supported using the <control-bus/> (feel free to open a new feature JIRA here

      However, you can get the data using JMX...

      <context:mbean-server id="mbs"/>
      <int-jmx:mbean-export id="integrationMbeanExporter" server="mbs" default-domain="my.domain"/>
      <int:channel id="testChannel">
      MBeanServer mBeanServer = this.context.getBean(MBeanServer.class);
      Integer queueSize = (Integer) mBeanServer.getAttribute(new ObjectName(
      		"my.domain:type=MessageChannel,name=testChannel"), "QueueSize");


      • #4
        Originally posted by Gary Russell View Post
        However, you can get the data using JMX...
        Thanks a lot, that works great!