Closed rimvydas-pranciulis closed 9 months ago
This must be missing some information because
I tried this both with the year-old 3.0.3 version and a current version of the starter, and the trace shows the wait time being respected both with and without the readahead setting.
I'm shutting down application manually, that's why JMS listener stops. Problem is that with "read ahead" JMS listener doesn't stop immediately after application shutdown is triggered, but it waits for extra 30 seconds (value of spring.jms.listener.receive-timeout
) and this prevents application from shutting down gracefully for this amount of time.
It is problem only with application shutdown, everything is good while it's running.
That's a rather better description. But I don't actually see any difference in behaviour when I added some exit code - readahead or not. Spring still appears always to wait for the timeout in its shutdown loop.
There's nothing this package can do to affect how either Spring works or how the MQ client code works; though it's not clear which piece has any "issue". I imagine that Spring is not aware of any background threads that the MQ client might have started up. Perhaps that's affecting the processing.
One thing I did try was to reset the timeout value in the code I used to exit from a listener. That did seem to speed up the exiting:
JmsListenerEndpointRegistry reg = MyApplication.context
.getBean("org.springframework.jms.config.internalJmsListenerEndpointRegistry",
JmsListenerEndpointRegistry.class);
if (reg != null) {
Set<String> ids = reg.getListenerContainerIds();
for (String id:ids) {
MessageListenerContainer cont = reg.getListenerContainer(id);
if (cont instanceof DefaultMessageListenerContainer) {
((DefaultMessageListenerContainer)cont).setReceiveTimeout(1);
}
}
}
Does code you pasted runs before or after shutdown of your application is triggered?
it runs before a System.exit(SpringApplication.exit(Application.context,...
used when I want to break out of the app.
Ok, so that it explains why it didn't worked when I tried to put into shutdown hook. I don't stop my app with exit statement, it is running on Kubernetes and that is where its lifecycle is controlled, so this workaround won't work.
Anyway, if that is not an issue of this library, but more related to core IBM MQ library then I'm closing this "issue". Thanks for taking a look.
I'm using Spring
DefaultMessageListenerContainer
for reading messages from IBM MQ and noticed that after enabling "read ahead" application doesn't stop immediately, but for waits for time configured underspring.jms.listener.receive-timeout
property (it is set to 30 seconds by default inmq-jms-spring-boot-starter
library). Without "read ahead" applications stops immediately.Code example:
Additional Spring JMS configuration:
Logs: