Results 1 to 4 of 4

Thread: Get size of a queue with Control Bus

  1. #1
    Join Date
    Feb 2012
    Posts
    2

    Default 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. #2
    Join Date
    Oct 2011
    Location
    Mumbai, India
    Posts
    213

    Default

    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.

  3. #3
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,017

    Default

    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");
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  4. #4
    Join Date
    Feb 2012
    Posts
    2

    Default

    Quote Originally Posted by Gary Russell View Post
    However, you can get the data using JMX...
    Thanks a lot, that works great!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •