'RabbitMQ Consumers disappear due to SocketTimeoutException
After the SocketTimeoutException the consumers from the queue disappear and they don't come back. The messages in the queue are not lost. Using spring configurations:
spring.rabbitmq.connectionTimeoutInMillis=2000
spring.rabbitmq.autoRecoveryEnabled=true
spring.rabbitmq.topologyRecoveryEnabled=false
spring.rabbitmq.networkRecoveryIntervalInMillis=10000
spring.rabbitmq.heartbeatTimeoutInSeconds=5
spring.rabbitmq.concurrentNumberOfConsumers=2
spring.rabbitmq.maxNumberOfConsumers=10
Using default Connection Factory from Spring AMQP RabbitMQ connection. This is how the listener Bean is created.
//Listener Configuration
@Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(ConnectionFactory connectionFactory) {
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
factory.setConcurrentConsumers(2);
factory.setMaxConcurrentConsumers(10);
Consumer<SimpleMessageListenerContainer> configurer = c -> c.setShutdownTimeout(600);
factory.setContainerConfigurer(configurer);
factory.setAdviceChain(workMessagesRetryInterceptor());
return factory;
}
//Listener handler logic
try {
genericService.sendMessage(message);
} catch (Exception e) {
throw new CustomException();
} catch (RequeueableException e) {
throw new CustomException();
} catch (GenericException ge){
message.setRetry(Message.retry);
retryService.sendMessageToRetryQueue(message);
} catch (Throwable e) {
throw new CustomException();
}
// genericService.sendMessage(message) logic
try {
doSomething();
} catch (RequeueableException re){
throw re;
} catch (NonRequeueableException nre){
throw nre;
} catch (Throwable t){
throw new NonRequeueableException(t);
} finally {
//Handle finally
}
//doSomething() logic
try {
// This method call will cause SocketTimeoutException
// Then it will come to catch block
xUtil.callAPI(message);
} catch(final Throwable t) {
throw new RequeueableException(t);
}
Is there a way to make the consumers reappear?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
