我只是使用这个示例代码来实现 Active MQ http://www.tomcatexpert.com/blog/2010/12/20/integrating-activemq-tomcat-using-global-jndi#ex-tomcat-server-xml。
能够与tomcat服务器成功发送和接收消息。
现在我需要实现共享文件系统主从。为此,我已按照以下步骤更改 activemq.xml 配置
在 activemq.xml 中添加了 networkConnector 和 transportConnector
<networkConnectors> <networkConnector name="My Queue" uri="static://(tcp://172.16.121.144:61616,tcp://172.16.121.146:61616)" /> </networkConnectors> <transportConnectors> <transportConnector name="openwire" uri="tcp://172.16.121.144:61616"/> </transportConnectors>
活动MQ.xml
<?xml version="1.0"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-5.3.0.xsd">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />
<broker xmlns="http://activemq.apache.org/schema/core"
brokerName="172.16.121.144"
dataDirectory="\\172.16.121.145\Shared Doc\amq\activemq\activemq-data"
schedulerSupport="false"
useJmx="true">
<destinationPolicy>
<policyMap>
<policyEntries>
<policyEntry topic=">">
<pendingSubscriberPolicy>
<vmCursor />
</pendingSubscriberPolicy>
</policyEntry>
<policyEntry queue=">">
<pendingQueuePolicy>
<vmQueueCursor />
</pendingQueuePolicy>
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>
<managementContext>
<managementContext createConnector="false"/>
</managementContext>
<networkConnectors>
<networkConnector name="My Queue" uri="static://(tcp://172.16.121.144:61616,tcp://172.16.121.146:61616)" />
</networkConnectors>
<persistenceAdapter>
<kahaDB directory="\\172.16.121.145\Shared Doc\amq\activemq\activemq-data\kahadb"/>
</persistenceAdapter>
<systemUsage>
<systemUsage>
<memoryUsage>
<memoryUsage limit="128 mb"/>
</memoryUsage>
<storeUsage>
<storeUsage limit="1 gb"/>
</storeUsage>
<tempUsage>
<tempUsage limit="100 mb"/>
</tempUsage>
</systemUsage>
</systemUsage>
<transportConnectors>
<transportConnector name="openwire" uri="tcp://172.16.121.144:61616"/>
</transportConnectors>
</broker>
</beans>
低于异常
INFO - ContextLoader - Root WebApplicationContext: initialization started INFO - XmlWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Tue Aug 20 12:31:15 IST 2013]; root of context hierarchy INFO - XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/jms-context.xml] INFO - DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@bc6a12:defining beans [connectionFactory,fooQueue,singleConnectionFactory,jmsTemplate,messageSenderService,jmsMessageDelegate,myMessageListener,org.springfra mework.jms.listener.DefaultMessageListenerContainer#0]; root of factory hierarchy INFO - DefaultLifecycleProcessor - Starting beans in phase 2147483647 INFO - DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1bc3ec9: defining beans [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,org.apache.activemq.xbean.XBeanBrokerService#0]; root of factory hierarchy INFO - BrokerService - Using Persistence Adapter: KahaDBPersistenceAdapter[\\172.16.121.145\SharedDoc\amq\activemq\activemq-data\ka hadb] INFO - BrokerService - ActiveMQ 5.4.1 JMS Message Broker (172.16.121.144) is starting INFO - BrokerService - For help or more information please see: http://activemq.apache.org/ INFO - TransportServerThreadSupport - Listening for connections at: tcp://01hw385526:61616 INFO - TransportConnector - Connector openwire Started INFO - DiscoveryNetworkConnector - Establishing network connection from vm://172.16.121.144?async=false&network=true to tcp://172.16.121.144:616 16 INFO - TransportConnector - Connector vm://172.16.121.144 Started INFO - DiscoveryNetworkConnector - Establishing network connection from vm://172.16.121.144?async=false&network=true to tcp://172.16.121.146:616 16 INFO - DemandForwardingBridgeSupport - 172.16.121.144 bridge to 172.16.121.144 stopped INFO - Transport - Transport failed: org.apache.activemq.transport.TransportDisposedIOException: Peer (vm://172.16.121.144#3) di sposed. org.apache.activemq.transport.TransportDisposedIOException: Peer (vm://172.16.121.144#3) disposed. at org.apache.activemq.transport.vm.VMTransport.stop(VMTransport.java:159) at org.apache.activemq.transport.vm.VMTransportServer$1.stop(VMTransportServer.java:81) at org.apache.activemq.transport.TransportFilter.stop(TransportFilter.java:65) at org.apache.activemq.transport.TransportFilter.stop(TransportFilter.java:65) at org.apache.activemq.transport.ResponseCorrelator.stop(ResponseCorrelator.java:132) at org.apache.activemq.util.ServiceSupport.dispose(ServiceSupport.java:43) at org.apache.activemq.network.DiscoveryNetworkConnector.onServiceAdd(DiscoveryNetworkConnector.java:137) at org.apache.activemq.transport.discovery.simple.SimpleDiscoveryAgent.start(SimpleDiscoveryAgent.java:77) at org.apache.activemq.network.DiscoveryNetworkConnector.handleStart(DiscoveryNetworkConnector.java:186) at org.apache.activemq.network.NetworkConnector$1.doStart(NetworkConnector.java:61) at org.apache.activemq.util.ServiceSupport.start(ServiceSupport.java:53) at org.apache.activemq.network.NetworkConnector.start(NetworkConnector.java:202) at org.apache.activemq.broker.BrokerService.startAllConnectors(BrokerService.java:2094) at org.apache.activemq.broker.BrokerService.start(BrokerService.java:518) at org.apache.activemq.xbean.XBeanBrokerService.afterPropertiesSet(XBeanBrokerService.java:60) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java :1581) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1522 ) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) at org.apache.xbean.spring.context.ResourceXmlApplicationContext.<init>(ResourceXmlApplicationContext.java:64) at org.apache.xbean.spring.context.ResourceXmlApplicationContext.<init>(ResourceXmlApplicationContext.java:52) at org.apache.activemq.xbean.XBeanBrokerFactory.createApplicationContext(XBeanBrokerFactory.java:96) at org.apache.activemq.xbean.XBeanBrokerFactory.createBroker(XBeanBrokerFactory.java:52) at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:71) at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:54) at org.apache.activemq.transport.vm.VMTransportFactory.doCompositeConnect(VMTransportFactory.java:121) at org.apache.activemq.transport.vm.VMTransportFactory.doConnect(VMTransportFactory.java:53) at org.apache.activemq.transport.TransportFactory.doConnect(TransportFactory.java:51) at org.apache.activemq.transport.TransportFactory.connect(TransportFactory.java:80) at org.apache.activemq.ActiveMQConnectionFactory.createTransport(ActiveMQConnectionFactory.java:243) at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:258) at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:230) at org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:178) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196) at $Proxy4.createConnection(Unknown Source) at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:184) at org.springframework.jms.listener.AbstractJmsListeningContainer.createSharedConnection(AbstractJmsListeningContainer.java:404) at org.springframework.jms.listener.AbstractJmsListeningContainer.establishSharedConnection(AbstractJmsListeningContainer.java:372) at org.springframework.jms.listener.DefaultMessageListenerContainer.establishSharedConnection(DefaultMessageListenerContainer.java:760) at org.springframework.jms.listener.AbstractJmsListeningContainer.doStart(AbstractJmsListeningContainer.java:279) at org.springframework.jms.listener.AbstractJmsListeningContainer.start(AbstractJmsListeningContainer.java:264) at org.springframework.jms.listener.DefaultMessageListenerContainer.start(DefaultMessageListenerContainer.java:561) at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:167) at org.springframework.context.support.DefaultLifecycleProcessor.access$1(DefaultLifecycleProcessor.java:154) at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:339) at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:143) at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:108) at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:926) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:467) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:897) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:873) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615) at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:958) at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1599) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722) INFO - TransportConnector - Connector vm://172.16.121.144 Stopped INFO - DemandForwardingBridgeSupport - Network connection between vm://172.16.121.144#2 and tcp://172.16.121.146:61616 shutdown due to a local error : org.apache.activemq.transport.TransportDisposedIOException: Peer (vm://172.16.121.144#2) disposed. INFO - DemandForwardingBridgeSupport - 172.16.121.144 bridge to Unknown stopped INFO - NetworkConnector - Network Connector My Queue Started INFO - BrokerService - ActiveMQ JMS Message Broker (172.16.121.144, ID:01hw385526-51685-1376982077589-0:0) started INFO - TransportConnector - Connector vm://localhost Started INFO - ContextLoader - Root WebApplicationContext: initialization completed in 3479 ms INFO - DispatcherServlet - FrameworkServlet 'jms-webapp': initialization started INFO - XmlWebApplicationContext - Refreshing WebApplicationContext for namespace 'jms-webapp-servlet': startup date [Tue Aug 20 12:31:18 IST 20 13]; parent: Root WebApplicationContext INFO - XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/jms-webapp-servlet.xml] INFO - DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@e975db: defining beans [jmsMessageSenderController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context .annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.contex t.annotation.internalCommonAnnotationProcessor,org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0,org.springframework.web .servlet.view.InternalResourceViewResolver#0,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; p arent: org.springframework.beans.factory.support.DefaultListableBeanFactory@bc6a12 INFO - DefaultAnnotationHandlerMapping - Mapped URL path [/send.html] onto handler 'jmsMessageSenderController' INFO - DispatcherServlet - FrameworkServlet 'jms-webapp': initialization completed in 375 ms Aug 20, 2013 12:31:19 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory C:\apache-tomcat-7.0.25\webapps\docs Aug 20, 2013 12:31:19 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory C:\apache-tomcat-7.0.25\webapps\examples Aug 20, 2013 12:31:19 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory C:\apache-tomcat-7.0.25\webapps\host-manager Aug 20, 2013 12:31:19 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory C:\apache-tomcat-7.0.25\webapps\manager Aug 20, 2013 12:31:19 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory C:\apache-tomcat-7.0.25\webapps\ROOT Aug 20, 2013 12:31:19 PM org.apache.coyote.AbstractProtocol start INFO: Starting ProtocolHandler ["http-bio-8080"] Aug 20, 2013 12:31:19 PM org.apache.coyote.AbstractProtocol start INFO: Starting ProtocolHandler ["ajp-bio-8009"] Aug 20, 2013 12:31:19 PM org.apache.catalina.startup.Catalina start INFO: Server startup in 4825 ms INFO - DiscoveryNetworkConnector - Establishing network connection from vm://172.16.121.144?async=false&network=true to tcp://172.16.121.146:616 16 INFO - TransportConnector - Connector vm://172.16.121.144 Started INFO - Transport - Transport failed: org.apache.activemq.transport.TransportDisposedIOException: Peer (vm://172.16.121.144#7) di sposed. org.apache.activemq.transport.TransportDisposedIOException: Peer (vm://172.16.121.144#7) disposed. at org.apache.activemq.transport.vm.VMTransport.stop(VMTransport.java:159) at org.apache.activemq.transport.vm.VMTransportServer$1.stop(VMTransportServer.java:81) at org.apache.activemq.transport.TransportFilter.stop(TransportFilter.java:65) at org.apache.activemq.transport.TransportFilter.stop(TransportFilter.java:65) at org.apache.activemq.transport.ResponseCorrelator.stop(ResponseCorrelator.java:132) at org.apache.activemq.util.ServiceSupport.dispose(ServiceSupport.java:43) at org.apache.activemq.network.DiscoveryNetworkConnector.onServiceAdd(DiscoveryNetworkConnector.java:137) at org.apache.activemq.transport.discovery.simple.SimpleDiscoveryAgent$1.run(SimpleDiscoveryAgent.java:164) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722) INFO - DemandForwardingBridgeSupport - Network connection between vm://172.16.121.144#6 and tcp://172.16.121.146:61616 shutdown due to a local error : org.apache.activemq.transport.TransportDisposedIOException: Peer (vm://172.16.121.144#6) disposed. INFO - TransportConnector - Connector vm://172.16.121.144 Stopped INFO - DemandForwardingBridgeSupport - 172.16.121.144 bridge to Unknown stopped