Search code examples
spring-batchspring-integration

How to recover JMS inbound-gateway containers on Active MQ server failure when number of retry is changed to limited


JMS Inbound gateway is used for request processing at worker side. CustomMessageListenerContainer class is configured to impose back off max attempts as limited. In some scenarios when active MQ server is not responding before max attempts limit reached container is being stopped with below message. "Stopping container for destination 'senExtractWorkerInGateway': back-off policy does not allow for further attempts."

Wondering is there any configuration available to recover these containers once the Active MQ is back available. sample configuration is given below.

<int-jms:inbound-gateway
    id="senExtractWorkerInGateway" 
    container-class="com.test.batch.worker.CustomMessageListenerContainer"
    connection-factory="jmsConnectionFactory"
    correlation-key="JMSCorrelationID"
    request-channel="senExtractProcessingWorkerRequestChannel"
    request-destination-name="senExtractRequestQueue" 
    reply-channel="senExtractProcessingWorkerReplyChannel"
    default-reply-queue-name="senExtractReplyQueue"
    auto-startup="false"
    concurrent-consumers="25"
    max-concurrent-consumers="25"
    reply-timeout="1200000" 
    receive-timeout="1200000"/>

Solution

  • You probably can emit some ApplicationEvent from the applyBackOffTime() of your CustomMessageListenerContainer when the super call returns false. This way you would know that something is wrong with ActiveMQ connection. At this moment you also need to stop() your senExtractWorkerInGateway - just autowire it into some controlling service as a Lifecycle. When you done fixing the connection problem, you just need to start this senExtractWorkerInGateway back. That CustomMessageListenerContainer is going to be started automatically.