Description
Hello. Please help me with the problem.
The problem is related to automatic reconnection.
I use Spring Boot 2.1.3, but it happens in version 2.1.6 and RabbitMQ with spring-boot-starter-amqp
Bin RabbitTemplate looks like this:
public final class ExtendedRabbitTemplate extends RabbitTemplate {
public ExtendedRabbitTemplate(final ConnectionFactory connectionFactory) {
super(connectionFactory);
}
@Override
protected final void replyTimedOut(final String correlationId) {
throw new RpcTimeoutException(String.format("Timeout on receiving reply to message with correlation id = %s", correlationId));
}
}
@Bean
public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
RabbitTemplate template = new ExtendedRabbitTemplate(connectionFactory);
template.setMessageConverter(producerJackson2MessageConverter());
template.setReplyTimeout(properties.getRpcMessagesReplyTimeout());
return template;
}
We use the following method to support rpc:
We want to use Direct ReplyTo with pseudo queues.
The scenario in which the normal behavior RabbitTemplate
- Initial state: Internet is available (access to the RMQ), the application is not running.
- Run the application.
- We send several messages and get answers. All is well.
- Turning off the Internet (access to the RMQ).
- We send several messages and get an exception after a timeout. Everything is also OK.
Scenario in which abnormal behavior is detected:
- Initial state: the Internet is not available(access to the RMQ), the application is not running
- Run the application.
- We send several messages and get exceptions org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused.
- Turn on the Internet (access to the RMQ)
- We send several messages and receive exceptions after a timeout. Therefore, no reconnection occurs.
I tried to figure out what was happening and found the following. The selected code block is executed 1 time at the first call. If the access was to the rabbit, then the first condition in the chain is satisfied. If we get an exception, then we get into the second condition block. Everything happens because at the first message(RQM is not available) we get replyAddress = null and usingFastReplyTo = false.
I hope this is enough.