Announcement Announcement Module
Collapse
No announcement yet.
Change concurrent-consumers on the fly Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      Great answer, Thanks a lot!!

      Comment


      • #4
        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)?

        Comment


        • #5
          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.

          Comment


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

            http://www.springsource.org/spring-amqp

            Comment

            Working...
            X