欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

springmvc+jms+activemq  

程序员文章站 2022-06-06 16:51:40
...

最近在做项目,采用SPRINGMVC+MYBATIS构架,需要实现异步消息功能,想到用JMS方式实现;

对JAVA的JMS进行了一下研究,现分享一下;

1、首先部署好SPRINGMVC环境;

所用JAR包如下:


springmvc+jms+activemq
            
    
    
         
 2、去官网下载ACTIVEMQ安装程序,官网提供的安装程序是ZIP包,将其解压到任意盘符(我这里指定E盘)

配置 MQ的环境变量

新建一个变量名为ANT_HOME值为E:\activemq;

修改变量名为Path值为E:\activemq\bin;

重新启动计算机,并进入BIN目录 运行文件 activemq.bat,看是否启动成功;

3、完成以上二步后,打开MYECLIPSE工具,建立测试包,包名为jms.activemq.myexample.spring再建立JMS所需的XML文件在此包下建立SpringJms;

4、建立发送消息类

 

package jms.activemq.myexample.spring;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

public class HelloWorldSender {
	public static void main(String args[]) throws Exception {
		ApplicationContext context = new ClassPathXmlApplicationContext(
				new String[] { "SpringJms/SpringJms.xml" });
		JmsTemplate jmsTemplate = (JmsTemplate) context.getBean("jmsTemplate");
		Destination destination = (Destination) context.getBean("destination");
		jmsTemplate.send(destination, new MessageCreator() {
			public Message createMessage(Session session) throws JMSException {
				return session.createTextMessage("大家好这个是测试!");
			}
		});
	}

}

 5、建立监听消息类

 

 

 

 

package jms.activemq.myexample.spring;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

public class TextListener implements MessageListener {

	@Override
	public void onMessage(Message message) {
		// TODO Auto-generated method stub
		TextMessage msg=null;
		try {
			if(message instanceof TextMessage){
				msg=(TextMessage)message;
				System.out.println("Reading message:"+msg.getText());
			} else {
                System.out.println("Message of wrong type: "
                        + message.getClass().getName());
            }
		} catch (JMSException e) {
			// TODO: handle exception
			System.out.println("JMSEXCEPTION:"+e.toString());
		} catch (Throwable e) {
			// TODO: handle exception
			System.out.println("EXCEPTION:"+e.getMessage());
		}
	}

}

 6、建立XML文件

 

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
	<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
		<property name="brokerURL">
			<value>tcp://localhost:61616</value>
		</property>

	</bean>

	<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
		<property name="connectionFactory">
			<ref bean="connectionFactory" />
		</property>
	</bean>
	<bean id="TestListener" class="jms.activemq.myexample.spring.TextListener">
	</bean>
		<bean id="listenerContainer"
		class="org.springframework.jms.listener.DefaultMessageListenerContainer">
		<property name="connectionFactory" ref="connectionFactory"></property>
		<property name="destination" ref="destination"></property>
		<property name="messageListener" ref="TestListener"></property>
	</bean>
	
	
	<bean id="destination" class="org.apache.activemq.command.ActiveMQQueue">
		<constructor-arg index="0">
			<value>HelloWorldQueue</value>
		</constructor-arg>
	</bean>
</beans>

 7、运行发送消息类

 

结果如下:

[DEBUG] 2013-11-01 12:12:23 :Initializing new StandardEnvironment
 [DEBUG] 2013-11-01 12:12:23 :Adding [systemProperties] PropertySource with lowest search precedence
 [DEBUG] 2013-11-01 12:12:23 :Adding [systemEnvironment] PropertySource with lowest search precedence
 [DEBUG] 2013-11-01 12:12:23 :Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
 [INFO ] 2013-11-01 12:12:23 :Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@4b222f: startup date [Fri Nov 01 12:12:23 CST 2013]; root of context hierarchy
 [DEBUG] 2013-11-01 12:12:23 :Initializing new StandardEnvironment
 [DEBUG] 2013-11-01 12:12:23 :Adding [systemProperties] PropertySource with lowest search precedence
 [DEBUG] 2013-11-01 12:12:23 :Adding [systemEnvironment] PropertySource with lowest search precedence
 [DEBUG] 2013-11-01 12:12:23 :Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
 [DEBUG] 2013-11-01 12:12:23 :Initializing new StandardEnvironment
 [DEBUG] 2013-11-01 12:12:23 :Adding [systemProperties] PropertySource with lowest search precedence
 [DEBUG] 2013-11-01 12:12:23 :Adding [systemEnvironment] PropertySource with lowest search precedence
 [DEBUG] 2013-11-01 12:12:23 :Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
 [INFO ] 2013-11-01 12:12:23 :Loading XML bean definitions from class path resource [SpringJms/SpringJms.xml]
 [DEBUG] 2013-11-01 12:12:23 :Using JAXP provider [com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl]
 [DEBUG] 2013-11-01 12:12:23 :Trying to resolve XML entity with public ID [-//SPRING//DTD BEAN//EN] and system ID [http://www.springframework.org/dtd/spring-beans.dtd]
 [DEBUG] 2013-11-01 12:12:23 :Trying to locate [spring-beans.dtd] in Spring jar
 [DEBUG] 2013-11-01 12:12:23 :Found beans DTD [http://www.springframework.org/dtd/spring-beans.dtd] in classpath: spring-beans.dtd
 [DEBUG] 2013-11-01 12:12:23 :Loading bean definitions
 [DEBUG] 2013-11-01 12:12:23 :Loaded 5 bean definitions from location pattern [SpringJms/SpringJms.xml]
 [DEBUG] 2013-11-01 12:12:23 :Bean factory for org.springframework.context.support.ClassPathXmlApplicationContext@4b222f: org.springframework.beans.factory.support.DefaultListableBeanFactory@b1b4c3: defining beans [connectionFactory,jmsTemplate,TestListener,listenerContainer,destination]; root of factory hierarchy
 [DEBUG] 2013-11-01 12:12:23 :Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@64f6cd]
 [DEBUG] 2013-11-01 12:12:23 :Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@2d9c06]
 [INFO ] 2013-11-01 12:12:23 :Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@b1b4c3: defining beans [connectionFactory,jmsTemplate,TestListener,listenerContainer,destination]; root of factory hierarchy
 [DEBUG] 2013-11-01 12:12:23 :Creating shared instance of singleton bean 'connectionFactory'
 [DEBUG] 2013-11-01 12:12:23 :Creating instance of bean 'connectionFactory'
 [DEBUG] 2013-11-01 12:12:23 :Eagerly caching bean 'connectionFactory' to allow for resolving potential circular references
 [DEBUG] 2013-11-01 12:12:23 :Getting BeanInfo for class [org.apache.activemq.ActiveMQConnectionFactory]
 [DEBUG] 2013-11-01 12:12:23 :Caching PropertyDescriptors for class [org.apache.activemq.ActiveMQConnectionFactory]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'alwaysSessionAsync' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'alwaysSyncSend' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'auditDepth' of type [int]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'auditMaximumProducerNumber' of type [int]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'blobTransferPolicy' of type [org.apache.activemq.blob.BlobTransferPolicy]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'brokerURL' of type [java.lang.String]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'class' of type [java.lang.Class]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'clientID' of type [java.lang.String]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'clientIDPrefix' of type [java.lang.String]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'closeTimeout' of type [int]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'copyMessageOnSend' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'disableTimeStampsByDefault' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'dispatchAsync' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'exceptionListener' of type [javax.jms.ExceptionListener]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'exclusiveConsumer' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'nestedMapAndListEnabled' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'objectMessageSerializationDefered' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'optimizeAcknowledge' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'optimizedMessageDispatch' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'password' of type [java.lang.String]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'prefetchPolicy' of type [org.apache.activemq.ActiveMQPrefetchPolicy]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'producerWindowSize' of type [int]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'properties' of type [java.util.Properties]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'redeliveryPolicy' of type [org.apache.activemq.RedeliveryPolicy]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'reference' of type [javax.naming.Reference]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'sendAcksAsync' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'sendTimeout' of type [int]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'stats' of type [org.apache.activemq.management.StatsImpl]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'statsEnabled' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'transformer' of type [org.apache.activemq.MessageTransformer]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'transportListener' of type [org.apache.activemq.transport.TransportListener]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'useAsyncSend' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'useCompression' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'useRetroactiveConsumer' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'userName' of type [java.lang.String]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'warnAboutUnstartedConnectionTimeout' of type [long]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'watchTopicAdvisories' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Finished creating instance of bean 'connectionFactory'
 [DEBUG] 2013-11-01 12:12:23 :Creating shared instance of singleton bean 'jmsTemplate'
 [DEBUG] 2013-11-01 12:12:23 :Creating instance of bean 'jmsTemplate'
 [DEBUG] 2013-11-01 12:12:23 :Eagerly caching bean 'jmsTemplate' to allow for resolving potential circular references
 [DEBUG] 2013-11-01 12:12:23 :Returning cached instance of singleton bean 'connectionFactory'
 [DEBUG] 2013-11-01 12:12:23 :Getting BeanInfo for class [org.springframework.jms.core.JmsTemplate]
 [DEBUG] 2013-11-01 12:12:23 :Caching PropertyDescriptors for class [org.springframework.jms.core.JmsTemplate]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'class' of type [java.lang.Class]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'connectionFactory' of type [javax.jms.ConnectionFactory]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'defaultDestination' of type [javax.jms.Destination]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'defaultDestinationName' of type [java.lang.String]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'deliveryMode' of type [int]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'deliveryPersistent' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'destinationResolver' of type [org.springframework.jms.support.destination.DestinationResolver]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'explicitQosEnabled' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'messageConverter' of type [org.springframework.jms.support.converter.MessageConverter]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'messageIdEnabled' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'messageTimestampEnabled' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'priority' of type [int]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'pubSubDomain' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'pubSubNoLocal' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'receiveTimeout' of type [long]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'sessionAcknowledgeMode' of type [int]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'sessionAcknowledgeModeName' of type [java.lang.String]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'sessionTransacted' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'timeToLive' of type [long]
 [DEBUG] 2013-11-01 12:12:23 :Invoking afterPropertiesSet() on bean with name 'jmsTemplate'
 [DEBUG] 2013-11-01 12:12:23 :Finished creating instance of bean 'jmsTemplate'
 [DEBUG] 2013-11-01 12:12:23 :Creating shared instance of singleton bean 'TestListener'
 [DEBUG] 2013-11-01 12:12:23 :Creating instance of bean 'TestListener'
 [DEBUG] 2013-11-01 12:12:23 :Eagerly caching bean 'TestListener' to allow for resolving potential circular references
 [DEBUG] 2013-11-01 12:12:23 :Finished creating instance of bean 'TestListener'
 [DEBUG] 2013-11-01 12:12:23 :Creating shared instance of singleton bean 'listenerContainer'
 [DEBUG] 2013-11-01 12:12:23 :Creating instance of bean 'listenerContainer'
 [DEBUG] 2013-11-01 12:12:23 :Eagerly caching bean 'listenerContainer' to allow for resolving potential circular references
 [DEBUG] 2013-11-01 12:12:23 :Returning cached instance of singleton bean 'connectionFactory'
 [DEBUG] 2013-11-01 12:12:23 :Getting BeanInfo for class [org.springframework.jms.listener.DefaultMessageListenerContainer]
 [DEBUG] 2013-11-01 12:12:23 :Caching PropertyDescriptors for class [org.springframework.jms.listener.DefaultMessageListenerContainer]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'acceptMessagesWhileStopping' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'active' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'activeConsumerCount' of type [int]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'autoStartup' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'beanName' of type [java.lang.String]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'cacheLevel' of type [int]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'cacheLevelName' of type [java.lang.String]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'class' of type [java.lang.Class]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'clientId' of type [java.lang.String]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'concurrency' of type [java.lang.String]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'concurrentConsumers' of type [int]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'connectionFactory' of type [javax.jms.ConnectionFactory]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'destination' of type [javax.jms.Destination]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'destinationName' of type [java.lang.String]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'destinationResolver' of type [org.springframework.jms.support.destination.DestinationResolver]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'durableSubscriptionName' of type [java.lang.String]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'errorHandler' of type [org.springframework.util.ErrorHandler]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'exceptionListener' of type [javax.jms.ExceptionListener]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'exposeListenerSession' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'idleConsumerLimit' of type [int]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'idleTaskExecutionLimit' of type [int]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'maxConcurrentConsumers' of type [int]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'maxMessagesPerTask' of type [int]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'messageListener' of type [java.lang.Object]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'messageSelector' of type [java.lang.String]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'pausedTaskCount' of type [int]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'phase' of type [int]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'pubSubDomain' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'pubSubNoLocal' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'receiveTimeout' of type [long]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'recoveryInterval' of type [long]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'registeredWithDestination' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'running' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'scheduledConsumerCount' of type [int]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'sessionAcknowledgeMode' of type [int]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'sessionAcknowledgeModeName' of type [java.lang.String]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'sessionTransacted' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'subscriptionDurable' of type [boolean]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'taskExecutor' of type [java.util.concurrent.Executor]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'transactionManager' of type [org.springframework.transaction.PlatformTransactionManager]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'transactionName' of type [java.lang.String]
 [DEBUG] 2013-11-01 12:12:23 :Found bean property 'transactionTimeout' of type [int]
 [DEBUG] 2013-11-01 12:12:23 :Creating shared instance of singleton bean 'destination'
 [DEBUG] 2013-11-01 12:12:23 :Creating instance of bean 'destination'
 [DEBUG] 2013-11-01 12:12:23 :Eagerly caching bean 'destination' to allow for resolving potential circular references
 [DEBUG] 2013-11-01 12:12:23 :Finished creating instance of bean 'destination'
 [DEBUG] 2013-11-01 12:12:23 :Returning cached instance of singleton bean 'TestListener'
 [DEBUG] 2013-11-01 12:12:23 :Invoking afterPropertiesSet() on bean with name 'listenerContainer'
 [DEBUG] 2013-11-01 12:12:23 :Finished creating instance of bean 'listenerContainer'
 [DEBUG] 2013-11-01 12:12:23 :Returning cached instance of singleton bean 'destination'
 [DEBUG] 2013-11-01 12:12:23 :Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [org.springframework.context.support.DefaultLifecycleProcessor@87c268]
 [DEBUG] 2013-11-01 12:12:23 :Returning cached instance of singleton bean 'listenerContainer'
 [DEBUG] 2013-11-01 12:12:23 :Returning cached instance of singleton bean 'lifecycleProcessor'
 [DEBUG] 2013-11-01 12:12:23 :Returning cached instance of singleton bean 'listenerContainer'
 [DEBUG] 2013-11-01 12:12:23 :Returning cached instance of singleton bean 'lifecycleProcessor'
 [INFO ] 2013-11-01 12:12:23 :Starting beans in phase 2147483647
 [DEBUG] 2013-11-01 12:12:23 :Starting bean 'listenerContainer' of type [class org.springframework.jms.listener.DefaultMessageListenerContainer]
 [DEBUG] 2013-11-01 12:12:24 :TCP consumer thread for tcp://localhost/127.0.0.1:61616 starting
 [DEBUG] 2013-11-01 12:12:24 :Sending: WireFormatInfo { version=5, properties={CacheSize=1024, CacheEnabled=true, SizePrefixDisabled=false, MaxInactivityDurationInitalDelay=10000, TcpNoDelayEnabled=true, MaxInactivityDuration=30000, TightEncodingEnabled=true, StackTraceEnabled=true}, magic=[A,c,t,i,v,e,M,Q]}
 [DEBUG] 2013-11-01 12:12:24 :Established shared JMS Connection
 [DEBUG] 2013-11-01 12:12:24 :Resumed paused task: org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker@80d1ff
 [DEBUG] 2013-11-01 12:12:24 :Received WireFormat: WireFormatInfo { version=10, properties={CacheSize=1024, MaxFrameSize=104857600, CacheEnabled=true, SizePrefixDisabled=false, TcpNoDelayEnabled=true, MaxInactivityDurationInitalDelay=10000, MaxInactivityDuration=30000, TightEncodingEnabled=true, StackTraceEnabled=true}, magic=[A,c,t,i,v,e,M,Q]}
 [DEBUG] 2013-11-01 12:12:24 :tcp://localhost/127.0.0.1:61616 before negotiation: OpenWireFormat{version=5, cacheEnabled=false, stackTraceEnabled=false, tightEncodingEnabled=false, sizePrefixDisabled=false}
 [DEBUG] 2013-11-01 12:12:24 :tcp://localhost/127.0.0.1:61616 after negotiation: OpenWireFormat{version=5, cacheEnabled=true, stackTraceEnabled=true, tightEncodingEnabled=true, sizePrefixDisabled=false}
 [DEBUG] 2013-11-01 12:12:24 :Successfully started bean 'listenerContainer'
 [DEBUG] 2013-11-01 12:12:24 :Publishing event in org.springframework.context.support.ClassPathXmlApplicationContext@4b222f: org.springframework.context.event.ContextRefreshedEvent[source=org.springframework.context.support.ClassPathXmlApplicationContext@4b222f: startup date [Fri Nov 01 12:12:23 CST 2013]; root of context hierarchy]
 [DEBUG] 2013-11-01 12:12:24 :Returning cached instance of singleton bean 'jmsTemplate'
 [DEBUG] 2013-11-01 12:12:24 :Returning cached instance of singleton bean 'destination'
 [DEBUG] 2013-11-01 12:12:24 :Sending: WireFormatInfo { version=5, properties={CacheSize=1024, CacheEnabled=true, SizePrefixDisabled=false, MaxInactivityDurationInitalDelay=10000, TcpNoDelayEnabled=true, MaxInactivityDuration=30000, TightEncodingEnabled=true, StackTraceEnabled=true}, magic=[A,c,t,i,v,e,M,Q]}
 [DEBUG] 2013-11-01 12:12:24 :TCP consumer thread for tcp://localhost/127.0.0.1:61616 starting
 [DEBUG] 2013-11-01 12:12:24 :Received WireFormat: WireFormatInfo { version=10, properties={CacheSize=1024, MaxFrameSize=104857600, CacheEnabled=true, SizePrefixDisabled=false, TcpNoDelayEnabled=true, MaxInactivityDurationInitalDelay=10000, MaxInactivityDuration=30000, TightEncodingEnabled=true, StackTraceEnabled=true}, magic=[A,c,t,i,v,e,M,Q]}
 [DEBUG] 2013-11-01 12:12:24 :tcp://localhost/127.0.0.1:61616 before negotiation: OpenWireFormat{version=5, cacheEnabled=false, stackTraceEnabled=false, tightEncodingEnabled=false, sizePrefixDisabled=false}
 [DEBUG] 2013-11-01 12:12:24 :tcp://localhost/127.0.0.1:61616 after negotiation: OpenWireFormat{version=5, cacheEnabled=true, stackTraceEnabled=true, tightEncodingEnabled=true, sizePrefixDisabled=false}
 [DEBUG] 2013-11-01 12:12:24 :Executing callback on JMS Session: ActiveMQSession {id=ID:lijiasheng-9750-1383279143931-0:1:1,started=false}
 [DEBUG] 2013-11-01 12:12:24 :Sending created message: ActiveMQTextMessage {commandId = 0, responseRequired = false, messageId = null, originalDestination = null, originalTransactionId = null, producerId = null, destination = null, transactionId = null, expiration = 0, timestamp = 0, arrival = 0, brokerInTime = 0, brokerOutTime = 0, correlationId = null, replyTo = null, persistent = false, type = null, priority = 0, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = null, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = false, readOnlyBody = false, droppable = false, text = 大家好这个是测试!}
 [DEBUG] 2013-11-01 12:12:24 :ID:lijiasheng-9750-1383279143931-0:1:1 sending message: ActiveMQTextMessage {commandId = 0, responseRequired = false, messageId = ID:lijiasheng-9750-1383279143931-0:1:1:1:1, originalDestination = null, originalTransactionId = null, producerId = ID:lijiasheng-9750-1383279143931-0:1:1:1, destination = queue://HelloWorldQueue, transactionId = null, expiration = 0, timestamp = 1383279144102, arrival = 0, brokerInTime = 0, brokerOutTime = 0, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = null, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, text = 大家好这个是测试!}
 [DEBUG] 2013-11-01 12:12:24 :ID:lijiasheng-9750-1383279143931-0:0:1:1 received message: MessageDispatch {commandId = 0, responseRequired = false, consumerId = ID:lijiasheng-9750-1383279143931-0:0:1:1, destination = queue://HelloWorldQueue, message = ActiveMQTextMessage {commandId = 5, responseRequired = true, messageId = ID:lijiasheng-9750-1383279143931-0:1:1:1:1, originalDestination = null, originalTransactionId = null, producerId = ID:lijiasheng-9750-1383279143931-0:1:1:1, destination = queue://HelloWorldQueue, transactionId = null, expiration = 0, timestamp = 1383279144102, arrival = 0, brokerInTime = 1383279144103, brokerOutTime = 1383279144104, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = null, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, text = 大家好这个是测试!}, redeliveryCounter = 0}
 [DEBUG] 2013-11-01 12:12:24 :Received message of type [class org.apache.activemq.command.ActiveMQTextMessage] from consumer [ActiveMQMessageConsumer { value=ID:lijiasheng-9750-1383279143931-0:0:1:1, started=true }] of session [ActiveMQSession {id=ID:lijiasheng-9750-1383279143931-0:0:1,started=true}]
 [DEBUG] 2013-11-01 12:12:24 :Bound value [org.springframework.jms.listener.LocallyExposedJmsResourceHolder@102799c] for key [org.apache.activemq.ActiveMQConnectionFactory@13ad33d] to thread [listenerContainer-1]
 Reading message:大家好这个是测试!
[DEBUG] 2013-11-01 12:12:24 :Removed value [org.springframework.jms.listener.LocallyExposedJmsResourceHolder@102799c] for key [org.apache.activemq.ActiveMQConnectionFactory@13ad33d] from thread [listenerContainer-1]
 [DEBUG] 2013-11-01 12:12:24 :Stopping transport tcp://localhost/127.0.0.1:61616
 [DEBUG] 2013-11-01 12:12:25 :Consumer [ActiveMQMessageConsumer { value=ID:lijiasheng-9750-1383279143931-0:0:1:1, started=true }] of session [ActiveMQSession {id=ID:lijiasheng-9750-1383279143931-0:0:1,started=true}] did not receive a message
 [DEBUG] 2013-11-01 12:12:26 :Consumer [ActiveMQMessageConsumer { value=ID:lijiasheng-9750-1383279143931-0:0:1:1, started=true }] of session [ActiveMQSession {id=ID:lijiasheng-9750-1383279143931-0:0:1,started=true}] did not receive a message
 [DEBUG] 2013-11-01 12:12:27 :Consumer [ActiveMQMessageConsumer { value=ID:lijiasheng-9750-1383279143931-0:0:1:1, started=true }] of session [ActiveMQSession {id=ID:lijiasheng-9750-1383279143931-0:0:1,started=true}] did not receive a message
 [DEBUG] 2013-11-01 12:12:28 :Consumer [ActiveMQMessageConsumer { value=ID:lijiasheng-9750-1383279143931-0:0:1:1, started=true }] of session [ActiveMQSession {id=ID:lijiasheng-9750-1383279143931-0:0:1,started=true}] did not receive a message
 [DEBUG] 2013-11-01 12:12:29 :Consumer [ActiveMQMessageConsumer { value=ID:lijiasheng-9750-1383279143931-0:0:1:1, started=true }] of session [ActiveMQSession {id=ID:lijiasheng-9750-1383279143931-0:0:1,started=true}] did not receive a message
 

这里日志采用LOG4J存储;

发送消息采用的是queue,我的理解为只要接收了消息就会删掉的;

不知道这样理解是否准确;

 

  • springmvc+jms+activemq
            
    
    
         
  • 大小: 76.3 KB