2

I'm running a Spring Boot (1.3.5) console application with an embedded ActiveMQ server (5.10.0), which works just fine for receiving messages. However, I'm having trouble shutting down the application without exceptions.

This exception is thrown once for each queue, after hitting Ctrl-C:

2016-09-21 15:46:36.561 ERROR 18275 --- [update]] o.apache.activemq.broker.BrokerService   : Failed to start Apache ActiveMQ ([my-mq-server, null], {})

java.lang.IllegalStateException: Shutdown in progress
    at java.lang.ApplicationShutdownHooks.add(ApplicationShutdownHooks.java:66)
    at java.lang.Runtime.addShutdownHook(Runtime.java:211)
    at org.apache.activemq.broker.BrokerService.addShutdownHook(BrokerService.java:2446)
    at org.apache.activemq.broker.BrokerService.doStartBroker(BrokerService.java:693)
    at org.apache.activemq.broker.BrokerService.startBroker(BrokerService.java:684)
    at org.apache.activemq.broker.BrokerService.start(BrokerService.java:605)
    at org.apache.activemq.transport.vm.VMTransportFactory.doCompositeConnect(VMTransportFactory.java:127)
    at org.apache.activemq.transport.vm.VMTransportFactory.doConnect(VMTransportFactory.java:56)
    at org.apache.activemq.transport.TransportFactory.connect(TransportFactory.java:65)
    at org.apache.activemq.ActiveMQConnectionFactory.createTransport(ActiveMQConnectionFactory.java:314)
    at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:329)
    at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:302)
    at org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:242)
    at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:283)
    at org.apache.activemq.jms.pool.PooledConnectionFactory$1.makeObject(PooledConnectionFactory.java:96)
    at org.apache.activemq.jms.pool.PooledConnectionFactory$1.makeObject(PooledConnectionFactory.java:93)
    at org.apache.commons.pool2.impl.GenericKeyedObjectPool.create(GenericKeyedObjectPool.java:1041)
    at org.apache.commons.pool2.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:357)
    at org.apache.commons.pool2.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:279)
    at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:243)
    at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:212)
    at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:180)
    at org.springframework.jms.listener.AbstractJmsListeningContainer.createSharedConnection(AbstractJmsListeningContainer.java:413)
    at org.springframework.jms.listener.AbstractJmsListeningContainer.refreshSharedConnection(AbstractJmsListeningContainer.java:398)
    at org.springframework.jms.listener.DefaultMessageListenerContainer.refreshConnectionUntilSuccessful(DefaultMessageListenerContainer.java:925)
    at org.springframework.jms.listener.DefaultMessageListenerContainer.recoverAfterListenerSetupFailure(DefaultMessageListenerContainer.java:899)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:1075)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
2016-09-21 15:46:36.564  INFO 18275 --- [update]] o.apache.activemq.broker.BrokerService   : Apache ActiveMQ 5.12.3 (my-mq-server, null) is shutting down

It seems as the DefaultMessageListenerContainer tries to start an ActiveMQ server which doesn't make sense to me. I've set the phase of the BrokerService to Integer.MAX_INT - 1 and the phase of DefaultJmsListeningContainerFactory to Integer.MAX_INT to make it go away before the ActiveMQ server is stopped.

I have this in my main():

public static void main(String[] args) {
    final ConfigurableApplicationContext context = SpringApplication.run(SiteServer.class, args);
    context.registerShutdownHook();
}

I've tried setting daemon to true as suggested here: Properly Shutting Down ActiveMQ and Spring DefaultMessageListenerContainer.

Any ideas? Thanks! =)

Community
  • 1
  • 1
user5806139
  • 531
  • 6
  • 14
  • `run()` is probably blocking until that CTRL-C is entered (maybe because of something SiteServer is doing?). You'll want to split it up using the second example in http://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/SpringApplication.html – Gus Sep 21 '16 at 16:07

1 Answers1

0

Found it. This problem occurs when the Camel context is shutdown after the BrokerService. Adding proper life cycle management so that Camel is shutdown before resolved the issue. Now everything is shutdown in a clean way without errors.

user5806139
  • 531
  • 6
  • 14
  • 1
    Do you have any example code of how you accomplished this? – matt forsythe Oct 02 '20 at 20:35
  • I created two classes implementing SmartLifecycle interface, one for CamelContext and one for ActiveMQ. The most important part is to implement getPhase() and return a value that is lower for ActiveMQ than it is for CamelContext. – user5806139 Dec 18 '20 at 08:53