I'm using the Spring AMQP request/reply messaging feature. I send a message and while waiting for a reply, a graceful shutdown commences. All indications are that the SimpleMessageListenerContainer I am using is stopping right away, and not waiting to see if the reply message arrives (to be clear, at this exact moment, the reply queue is empty so the consumer doesn't have any message(s) to process). I immediately see log messages such as "Waiting for workers to finish.", "Successfully waited for workers to finish." and "Bean 'myReplyContainer' completed its stop procedure".
I know that, in general, a graceful shutdown is happening because I not only have it configured that way, but the log message "Bean 'webServerStartStop' completed its stop procedure" does not appear until all of the in-flight HTTP requests are complete.
My reply container is configuration like so:
@Bean
public SimpleMessageListenerContainer myReplyContainer(ConnectionFactory connectionFactory,
RabbitTemplate myTemplate,
Queue fromQueue) {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.setQueues(fromQueue);
container.setMessageListener(myTemplate);
container.setPrefetchCount(15); // Arbitrary
container.setRecoveryInterval(15_000L);
container.setDeclarationRetries(Integer.MAX_VALUE);
container.setFailedDeclarationRetryInterval(15_000);
return container;
}
Where "fromQueue" is simply an AnonymousQueue and myTemplate is a RabbitTemplate with both a reply address and a reply timeout set (plus a JSON message converter).
My request message is sent with a 15 seconds time-to-live expiration. My goal is to have the graceful shutdown of the reply container wait at least that long so that it has a chance to process the reply message (as it stands now, the reply message is effectively lost). I can't see to find any configuration setting that allows me to do that.
What might I be missing?
This is something what is not implemented in Spring AMQP.
That SimpleMessageListenerContainer
is just not aware about pending replies in the RabbitTemplate
.
Please, raise a GH issue and we will think what can be done.
Nothing comes to my mind right now as a workaround for you.
You may try to use request/reply, but not via fixed reply queue rather using a temporary one for each request: https://docs.spring.io/spring-amqp/reference/amqp/request-reply.html#page-title