Pand005
Pand005

Reputation: 1175

How does SimpleMessageListenerContainer handleMesage() works?

I have a question on how SimpleMessageListenerContainer handleMesage works? my problem scenario is, I have 1000 messages(m1, m2... m100) in queue then started consumer (5 concurrent consumers) and acknowledgeMode='NONE' in this scenario,

  1. does handleMesage consume 5 messages at a time (m1,m2,m3,m4,m5) then next 5 messages, and so on... ?

  2. Does container creates 5 Receiver instances?

  3. Would like to know end of the handle message where control will goes?

Can you please let me know these.. because we couldn't able to see the messages as soon as Consumer starts in RMQ MNGMT console.... our code inside handleMesage method will take atleast some seconds to process each request.

<bean id="sampleListenerContainer"
        class="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer">
        <property name="connectionFactory" ref="connectionFactory" />
        <property name="queueNames">
            <array>
                <value>TEST_QUEUE</value>
            </array>
        </property>
        <property name="messageListener" ref="messageListenerAdaptor" />
        <property name="acknowledgeMode" value="NONE" />
        <property name="concurrentConsumers" value="5" /> 
    </bean>

    <!-- message listener -->
    <bean id="messageListenerAdaptor"
        class="org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter">
        <property name="delegate" ref="listenerPojo" />
        <property name="messageConverter" ref="messageConverter" />
    </bean>

    <bean id="listenerPojo"
        class="com.amqp.consumer.Receiver" >
    </bean>

Upvotes: 2

Views: 1260

Answers (1)

Gary Russell
Gary Russell

Reputation: 174574

  1. With version 1.3 and later, each consumer gets prefetch messages at a time (the broker sends them round robin)

  2. Yes but they're called consumers, not receivers

  3. When the listener method exits, the consumer grabs the next message, this frees up the amqp-client thread so it can get another message from the broker.

With ackmode NONE, it depends on which version of Spring AMQP you are using how messages are delivered to the consumer.

With versions prior to 1.3, all 1000 messages would immediately be sent to the container (200 for each consumer).

After version 1.3.0, the number of messages sent to each consumer depends on the prefetchCount property (default 1); there will actually be prefetch+1 messages removed from the broker for each consumer.

Understand that AcknowledgeMode="NONE" means you can lose messages because the broker automatically acks the messages when they are sent to the consumer. Any messages sitting in the consumer (prefetch) will be lost if the server crashes.

Upvotes: 1

Related Questions