I have a Spring Boot app which programatically starts a few JMS listeners. From config:
@Override
public void configureJmsListeners(final JmsListenerEndpointRegistrar registrar) {
final List<String> allQueueNames = getAllQueueNames();
for (final String queueName : allQueueNames) {
LOG.info("Creating JMSListener for queueName: '{}'", queueName);
final SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
endpoint.setId(queueName + "_endpoint");
endpoint.setDestination(queueName);
endpoint.setMessageListener(message -> onMessage((TextMessage) message));
registrar.registerEndpoint(endpoint);
}
}
@Bean
@Override
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(
final ConnectionFactory connectionFactory,
final DefaultJmsListenerContainerFactoryConfigurer defaultJmsListenerContainerFactoryConfigurer) {
final DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setSessionTransacted(true);
factory.setErrorHandler(t -> errorService.handleException(t));
defaultJmsListenerContainerFactoryConfigurer.configure(factory, connectionFactory);
return factory;
}
Given certain circumstances, e.g. db failing, I have to stop the listeners from processing any more messages and STOP THE APP.
I use the following, from errorService, to stop the application:
((ConfigurableApplicationContext)(this).applicationContext).close();
However the application does not stop due to:
Still waiting for shutdown of 1 message listener invokers
...which repeats forever.
Is there any way that I can stop the application during processing of the JMS Message? I thought that stopping the application in the Listeners errorHandler would have worked but obviously the application thinks that the Listener is still processing the message and therefore will not stop.
Thanks in advance