为什么我的ActiveMQ正在关闭我的Tomcat?

时间:2015-01-27 14:17:17

标签: java tomcat activemq

我在使用ActiveMQ的Tomcat容器中有一个虚拟webapp。

我遇到的问题是,ActiveMQ无法关闭并强制关闭我的Tomcat。

这是来自catalina.log的日志:

    INFO 2015-01-21 17:35:04,072 - ActiveMQ Message Broker (localhost, ID:app-46388-1421875096431-0:1) is shutting down - org.apache.activemq.broker.BrokerService.stop(BrokerService.java:560) - ActiveMQ ShutdownHook
    DEBUG 2015-01-21 17:35:04,072 - Caught exception, must be shutting down: java.lang.IllegalStateException: Shutdown in progress - org.apache.activemq.broker.BrokerService.removeShutdownHook(BrokerService.java:1950) - ActiveMQ ShutdownHook
    Jan 21, 2015 5:35:04 PM org.apache.coyote.http11.Http11Protocol pause
    INFO: Pausing Coyote HTTP/1.1 on http-127.0.0.1-8080
    Jan 21, 2015 5:35:04 PM org.apache.coyote.http11.Http11Protocol pause
    INFO: Pausing Coyote HTTP/1.1 on http-209.159.149.98-8080
    DEBUG 2015-01-21 17:35:04,075 - Shutting down VM connectors for broker: localhost - org.apache.activemq.transport.vm.VMTransportFactory.stopped(VMTransportFactory.java:227) - ActiveMQ ShutdownHook
    DEBUG 2015-01-21 17:35:04,076 - Stopping connection: vm://localhost#0 - org.apache.activemq.broker.TransportConnection.doStop(TransportConnection.java:964) - ActiveMQ Task
    DEBUG 2015-01-21 17:35:04,077 - Stopped transport: vm://localhost#0 - org.apache.activemq.broker.TransportConnection.doStop(TransportConnection.java:980) - ActiveMQ Task
    DEBUG 2015-01-21 17:35:04,077 - Cleaning up connection resources: vm://localhost#0 - org.apache.activemq.broker.TransportConnection.doStop(TransportConnection.java:1013) - ActiveMQ Task
    DEBUG 2015-01-21 17:35:04,077 - remove connection id: ID:app-46388-1421875096431-2:1 - org.apache.activemq.broker.TransportConnection.processRemoveConnection(TransportConnection.java:713) - ActiveMQ Task
    DEBUG 2015-01-21 17:35:04,077 - localhost removing consumer: ID:app-46388-1421875096431-2:1:1:1 for destination: queue://mydomain.mail.sender - org.apache.activemq.broker.region.AbstractRegion.removeConsumer(AbstractRegion.java:322) - ActiveMQ Task
    DEBUG 2015-01-21 17:35:04,077 - remove sub: QueueSubscription: consumer=ID:app-46388-1421875096431-2:1:1:1, destinations=1, dispatched=0, delivered=0, pending=0, lastDeliveredSeqId: 0, dequeues: 0, dispatched: 0, inflight: 0 - org.apache.activemq.broker.region.Queue.removeSubscription(Queue.java:430) - ActiveMQ Task
    DEBUG 2015-01-21 17:35:04,079 - localhost removing consumer: ID:app-46388-1421875096431-2:1:-1:1 for destination: topic://ActiveMQ.Advisory.TempQueue,topic://ActiveMQ.Advisory.TempTopic - org.apache.activemq.broker.region.AbstractRegion.removeConsumer(AbstractRegion.java:322) - ActiveMQ Task
    DEBUG 2015-01-21 17:35:04,079 - Connection Stopped: vm://localhost#0 - org.apache.activemq.broker.TransportConnection.doStop(TransportConnection.java:1023) - ActiveMQ Task
    INFO 2015-01-21 17:35:04,079 - Connector vm://localhost Stopped - org.apache.activemq.broker.TransportConnector.stop(TransportConnector.java:288) - ActiveMQ ShutdownHook
    INFO 2015-01-21 17:35:04,079 - ActiveMQ Message Broker (localhost, ID:app-46388-1421875096431-0:1) is shutting down - org.apache.activemq.broker.BrokerService.stop(BrokerService.java:560) - ActiveMQ ShutdownHook
    DEBUG 2015-01-21 17:35:04,079 - Caught exception, must be shutting down: java.lang.IllegalStateException: Shutdown in progress - org.apache.activemq.broker.BrokerService.removeShutdownHook(BrokerService.java:1950) - ActiveMQ ShutdownHook
    INFO 2015-01-21 17:35:04,081 - PListStore:activemq-data/localhost/tmp_storage stopped - org.apache.activemq.store.kahadb.plist.PListStore.doStop(PListStore.java:307) - ActiveMQ ShutdownHook
    INFO 2015-01-21 17:35:04,081 - Stopping async queue tasks - org.apache.activemq.store.kahadb.KahaDBStore.doStop(KahaDBStore.java:206) - ActiveMQ ShutdownHook
    INFO 2015-01-21 17:35:04,081 - Stopping async topic tasks - org.apache.activemq.store.kahadb.KahaDBStore.doStop(KahaDBStore.java:220) - ActiveMQ ShutdownHook
    INFO 2015-01-21 17:35:04,082 - Stopped KahaDB - org.apache.activemq.store.kahadb.KahaDBStore.doStop(KahaDBStore.java:246) - ActiveMQ ShutdownHook
    DEBUG 2015-01-21 17:35:04,082 - Checkpoint started. - org.apache.activemq.store.kahadb.MessageDatabase.checkpointUpdate(MessageDatabase.java:1131) - ActiveMQ ShutdownHook
    DEBUG 2015-01-21 17:35:04,090 - Checkpoint done. - org.apache.activemq.store.kahadb.MessageDatabase.checkpointUpdate(MessageDatabase.java:1244) - ActiveMQ ShutdownHook
    INFO 2015-01-21 17:35:04,480 - ActiveMQ JMS Message Broker (localhost, ID:app-46388-1421875096431-0:1) stopped - org.apache.activemq.broker.BrokerService.stop(BrokerService.java:628) - ActiveMQ ShutdownHook
    INFO 2015-01-21 17:35:04,481 - ActiveMQ JMS Message Broker (localhost, ID:app-46388-1421875096431-0:1) stopped - org.apache.activemq.broker.BrokerService.stop(BrokerService.java:628) - ActiveMQ ShutdownHook
    Jan 21, 2015 5:35:05 PM org.apache.catalina.core.StandardService stop
    INFO: Stopping service Catalina

DEBUG 2015-01-21 17:35:05,345 - Shutting down JMS listener container - org.springframework.jms.listener.AbstractJmsListeningContainer.shutdown(AbstractJmsListeningContainer.java:190) - Thread-20
 DEBUG 2015-01-21 17:35:05,345 - Closing JMS MessageConsumers - org.springframework.jms.listener.SimpleMessageListenerContainer.doShutdown(SimpleMessageListenerContainer.java:303) - Thread-20
 DEBUG 2015-01-21 17:35:05,350 - remove: ID:app-46388-1421875096431-2:1:1:1, lastDeliveredSequenceId:0 - org.apache.activemq.ActiveMQMessageConsumer.doClose(ActiveMQMessageConsumer.java:661) - Thread-20
 DEBUG 2015-01-21 17:35:05,351 - Closing JMS Sessions - org.springframework.jms.listener.SimpleMessageListenerContainer.doShutdown(SimpleMessageListenerContainer.java:308) - Thread-20
 DEBUG 2015-01-21 17:35:05,351 - Failed to send remove command: javax.jms.JMSException: Peer (vm://localhost#1) disposed. - org.apache.activemq.AdvisoryConsumer.dispose(AdvisoryConsumer.java:58) - Thread-20
javax.jms.JMSException: Peer (vm://localhost#1) disposed.
    at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:62)
    at org.apache.activemq.ActiveMQConnection.doAsyncSendPacket(ActiveMQConnection.java:1259)
    at org.apache.activemq.ActiveMQConnection.asyncSendPacket(ActiveMQConnection.java:1251)
    at org.apache.activemq.AdvisoryConsumer.dispose(AdvisoryConsumer.java:56)
    at org.apache.activemq.ActiveMQConnection.close(ActiveMQConnection.java:615)
    at org.springframework.jms.connection.ConnectionFactoryUtils.releaseConnection(ConnectionFactoryUtils.java:81)
    at org.springframework.jms.listener.AbstractJmsListeningContainer.shutdown(AbstractJmsListeningContainer.java:219)
    at org.springframework.jms.listener.AbstractJmsListeningContainer.destroy(AbstractJmsListeningContainer.java:149)
    at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:151)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:487)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:462)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:430)
    at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:853)
    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:831)
    at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:794)
    at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:361)
    at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:70)
    at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:3882)
    at org.apache.catalina.core.StandardContext.stop(StandardContext.java:4523)
    at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:924)
    at org.apache.catalina.startup.HostConfig.undeployApps(HostConfig.java:1191)
    at org.apache.catalina.startup.HostConfig.stop(HostConfig.java:1162)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:313)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1086)
    at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1098)
    at org.apache.catalina.core.StandardEngine.stop(StandardEngine.java:448)
    at org.apache.catalina.core.StandardService.stop(StandardService.java:584)
    at org.apache.catalina.core.StandardServer.stop(StandardServer.java:744)
    at org.apache.catalina.startup.Catalina.stop(Catalina.java:628)
    at org.apache.catalina.startup.Catalina$CatalinaShutdownHook.run(Catalina.java:671)
Caused by: org.apache.activemq.transport.TransportDisposedIOException: Peer (vm://localhost#1) disposed.
    at org.apache.activemq.transport.vm.VMTransport.oneway(VMTransport.java:90)
    at org.apache.activemq.transport.MutexTransport.oneway(MutexTransport.java:40)
    at org.apache.activemq.transport.ResponseCorrelator.oneway(ResponseCorrelator.java:60)
    at org.apache.activemq.ActiveMQConnection.doAsyncSendPacket(ActiveMQConnection.java:1257)
    ... 29 more
 DEBUG 2015-01-21 17:35:05,352 - Could not close JMS Connection - org.springframework.jms.connection.ConnectionFactoryUtils.releaseConnection(ConnectionFactoryUtils.java:84) - Thread-20

这是我的ActiveMQ配置(applicationContext.xml):

<amq:redeliveryPolicy id="redeliveryPolicyTwoTimes" maximumRedeliveries="2" redeliveryDelay="2000"/>

<amq:connectionFactory id="jmsFactory" brokerURL="vm://localhost:61616" messagePrioritySupported="true">
    <amq:redeliveryPolicy>
        <ref bean="redeliveryPolicyTwoTimes"/>
    </amq:redeliveryPolicy>
</amq:connectionFactory>

<amq:queue id="jmsDestinationMailSender" physicalName="mydomain.mail.sender"/>

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:1)

ActiveMQ注册自己的关闭挂钩,并在进程终止时自动停止。因此,在调用stop()之前它已经停止,并且出现异常。

如果你通过Spring手动停止它,那么你应该通过设置属性useShutdownHook =“false”来禁用关闭钩子

 useShutdownHook="false"

参考,请通过以下链接: - http://activemq.apache.org/broker-uri.html

示例代码: -

<amq:broker useJmx="false" persistent="false" useShutdownHook="false">

...

</amq:broker>

答案 1 :(得分:0)

请参阅Apache Camel的示例,了解如何在WAR应用程序中嵌入ActiveMQ代理:http://camel.apache.org/activemq-camel-tomcat.html

您不需要使用Camel,因此您可以从WAR中删除该部分,但关键是您需要正确设置ActiveMQ代理,例如我们在broker.xml文件中执行的操作完成。