Search code examples
rabbitmqspring-amqpspring-rabbit

Spring AMQP Listener Timeout


I have a requirement for handling SpringAMQP listener timeout capability i.e We sends a message from producer , The consumer listener thread of Spring AMQP receives the message but say takes lot of time to execute itself and get hanged , Which will eventually lead to Listener thread being rendered unusable.

So is there any way that we have any consumer timeout setting provided by Spring AMQP so that the listener thread is freed again after given timeout time


Solution

  • Indeed you can mention the timeout using spring-amqp, here is how.

    <bean id="connectionFactory"  class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
        <property name="connectionTimeout"      value="1000" />
        <property name="concurrency"            value="16" /> <!-- in milliseconds -->
        <property name="recoveryInterval"       value="5000" />
    </bean>
    

    NOTE: If you are having limited consumer count and using manual ack and not sending the ack signal back for some reason, timeout might occur; it means you are holding the thread and not releasing it which will also impact your performance.

    More here

    1. doc
    2. api