Results 1 to 6 of 6

Thread: Change concurrent-consumers on the fly

  1. #1
    Join Date
    Apr 2012
    Posts
    9

    Default Change concurrent-consumers on the fly

    Is there any way to increase the number of consumers without stopping Tomcat?

    Like hot deploy, so you can change the configuration file:
    from <int-amqp:inbound-channel-adapter concurrent-consumers="10"
    to <int-amqp:inbound-channel-adapter concurrent-consumers="30"

    Thanks

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

    Default

    Yes.

    Declare an external listener container and inject it into the adapter...

    Code:
        <int-amqp:inbound-channel-adapter channel="fromRabbit" 
    		listener-container="listener.container" />
    	
        <bean id="listenerContainer" class="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer">
            <property name="channelTransacted" value="false" />
            <property name="concurrentConsumers" value="2" />
            <property name="prefetchCount" value="1" />
            <property name="connectionFactory" ref="connectionFactory" />
            <property name="acknowledgeMode" value="AUTO" />
            <property name="queues" value="si.test.queue" />
            <property name="autoStartup" value="true" />
        </bean>
    Get a reference to the SMLC, then execute stop(), change the consumers, and start()...

    Code:
    @Autowire private SimpleMessageListenerContainer container;
    
    ...
    
        container.stop();
        container.setConcurrentConsumers(newConsumers);
        container.start();
    Or, use a <control-bus/> and send "@listenerContainer.stop()" etc to it.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  3. #3
    Join Date
    Apr 2012
    Posts
    9

    Default

    Great answer, Thanks a lot!!

  4. #4

    Default

    Hi,

    Trying the control bus method above failed for me. I think setConcurrentConsumers() need to be marked with @ManagedOperation fort this to work, no?
    Maybe it's even better to extend SimpleMessageListenerContainer and add a method that exectues the three steps (stop, reconfigure and start)?

  5. #5
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,036

    Default

    You are correct; that method is not available via the control-bus.

    Yes, a subclass would work (with the control-bus too).

    Please be aware that we recently found an issue (https://jira.springsource.org/browse/AMQP-275) where a race condition can cause some messages to remain un-ack'd when stopping the container. They are not lost, but won't be redelivered until the connection is reset.

    This is fixed in 1.1.3.RELEASE which should be available later this week.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  6. #6
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,036

    Default

    spring-amqp 1.1.3.RELEASE, including this fix, is now available

    http://www.springsource.org/spring-amqp
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

Tags for this Thread

Posting Permissions

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