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

  • Get size of a queue with Control Bus

    Hi,

    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

    Code:
    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.

    Code:
    <si:channel id="readEventChannel" >
    	<si:queue  />
    </si:channel>
    
    <bean id="applicationMonitor" class="com.example.ApplicationMonitor">
    	<property name="controlChannel" ref="controlChannel" />
    	<property name="controlOutputChannel" ref="controlOutputChannel" />
    	 <property name="queueList">
    		<list>
    			<ref bean="readEventChannel" />
    		</list>
    	</property>
    </bean>
    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

    Code:
    public class ApplicationControlPanel implements BeanFactoryAware {
    
    	private BeanFactory factory;
    	
    	@ManagedOperation
    	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.

    Comment


    • #3
      This is not currently supported using the <control-bus/> (feel free to open a new feature JIRA here https://jira.springsource.org/browse/INT).

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

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

      Comment


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

        Comment

        Working...
        X