关闭Apache ActiveMQ

时间:2016-09-21 15:00:22

标签: java spring listener activemq

我正在运行一个带有嵌入式ActiveMQ服务器(5.10.0)的Spring Boot(1.3.5)控制台应用程序,它可以很好地接收消息。但是,我无法例外地关闭应用程序。

在按下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

似乎DefaultMessageListenerContainer尝试启动一个对我没有意义的ActiveMQ服务器。我已将BrokerService的阶段设置为Integer.MAX_INT - 1,并将DefaultJmsListeningContainerFactory的阶段设置为Integer.MAX_INT,以使其在ActiveMQ服务器停止之前消失。

我在main()中有这个:

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

我已尝试按照此处的建议将守护程序设置为true:Properly Shutting Down ActiveMQ and Spring DefaultMessageListenerContainer

有什么想法吗?谢谢! =)

1 个答案:

答案 0 :(得分:0)

找到它。在 BrokerService之后关闭Camel上下文时会发生此问题。添加适当的生命周期管理,以便在解决问题之前关闭Camel。现在一切都以干净的方式关闭而没有错误。