0

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

Lawrence Tierney
  • 856
  • 1
  • 12
  • 30
  • 1
    You need to take a thread dump; most likely the listener thread is stuck in user code. If it's interruptible, you can configure the container to use a task executor that will interrupt the threads on context close(). If the thread is not interruptible (e.g. reading from a socket with no timeout), you are out of luck. First step is to find what the thread is doing. – Gary Russell Sep 14 '17 at 14:28
  • Thanks I'll look into that – Lawrence Tierney Sep 15 '17 at 07:41
  • 1
    Did you ever manage to fix this? I'm having the same problem, so I would be interested to know. – Pieter Oct 04 '18 at 13:10

0 Answers0