`
aslijiasheng
  • 浏览: 56954 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

springmvc+jms+activemq

 
阅读更多

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

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

1、首先部署好SPRINGMVC环境;

所用JAR包如下:



 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,我的理解为只要接收了消息就会删掉的;

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

 

  • 大小: 76.3 KB
3
2
分享到:
评论
4 楼 sosojustdo 2013-11-02  
ActiveMQ据说在多线程,高并发下容易挂掉,不知道是不是,没有亲身压力去测试过。
3 楼 yzxqml 2013-11-01  
想了解了解,有空多交流
2 楼 aslijiasheng 2013-11-01  
哦,明白了,受教受教
1 楼 caizi12 2013-11-01  
jms消息可以为一对一和一对多两种形式,若为一对一时消费后即会删除

相关推荐

    SpringMVC+JMS(ActiveMQ)整合的Demo

    SpringMVC+JMS(ActiveMQ)整合的Demo,程序可运行。但不排除有一些小问题,请批评指正。

    SpringMvc+redis+activeMq实现消息发布订阅(测试通过)

    SpringMvc+redis+activeMq实现消息发布订阅(测试通过) redis和activeMq jms各自需要的Jar包在其它资源中上传,大家可以下载。 这个例子拿到项目中可直接用

    JMS+ActiveMQ+Spring 完整样例代码

    完整的 jms 与 spring 相结合,并且使用 activeMQ 作为外部消息提供者的样例代码,内涵完整的spring的jar 包,适合初学者借鉴

    JMS+activeMQ消息中间件

    最全的基于spring mvc的JMS+activeMQ实现的消息中间件代码例子,源程序和apache-activemq-5.10.0-bin.zip

    activeMQ-JMS实例

    该例子是本人写的一个关于使用springMVC搭建的activeMQ的JSM实例,希望对学校JMS的朋友有所帮助。

    Spring 实现远程访问详解——jms和activemq

    本章我将通过spring jms和activemq实现单Web项目服务器间异步访问和多Web项目服务器间异步访问。 一. 简介 1. 什么是Apache ActiveMq Apache ActiveMq是最流行和最强大的开源消息和集成服务器。同时Apache ActiveMq...

    2019品优购.txt

    前端:angularJS + Bootstrap 后台:SSM( springmvc+spring+mybatis) 数据库:mysql,使用mycat读写分离 开发模式:SOA 服务中间件:dubbox,需要和zookeeper配合使用 注册中心:zookeeper 消息中间件:Activemq,...

    黑马品优购电商项目全套资源

    消息中间件:Activemq,使用弹簧JMS 负载均衡:nginx的的 搜索:Solr中的集群(solrCloud),配合动物园管理员搭建,使用弹簧-数据-索洛 缓存:Redis的的集群,使用弹簧数据redis的的 图片存储:fastDFS集群 | |...

    黑马49期全系列包括品优购

    zookeeper 消息中间件:Activemq,使用spring-jms 负载均衡:nginx 搜索:solr集群(solrCloud),配合zookeeper搭建, 使用spring-data-solor 缓存:redis集群,使用spring-data-redis 图片存储:fastDFS集群 网页...

    JMS相关,教程,例子,学习笔记

    JMS教程,学习笔记,基于XML和JMS的异构数据交换集成

    黑马品优购项目

    消息中间件:Activemq,使用spring-jms 负载均衡:nginx 搜索:solr集群(solrCloud),配合zookeeper搭建, 使用spring-data-solor 缓存:redis集群,使用spring-data-redis 图片存储:fastDFS集群 网页静态化:...

    2小时学会Spring+Dubbo整合ActiveMQ消息队列

    本课程全程使用目前比较流行的开发工具idea进行开发,涉及到目前互联网项目中最常用的高并发解决方案技术, 如 dubbo,redis,solr,freemarker,activeMQ,springBoot框架,微信支付,nginx负载均衡,电商活动秒杀,spring...

    JavaEE企业级开发的面试题汇总

    JavaEE企业级开发的面试题汇总,内容...5.JMS中间件:关于ActiveMQ消息中间件相关的面试题 6.RPC中间件DUBBO的面试题 7.注册中心zookeeper的面试题 8.MAVN和solr的面试题 9.分布式事务、分面式锁、高并发相关的面试题等

    全新JAVAEE大神完美就业实战课程 超150G巨制课程轻松实战JAVAEE课程 就业部分.txt

    day08_activeMQ介绍_搭建_解决同步索引库问题 day09_FreeMark入门_静态化页面标签介绍_静态化页面实现 day10_Nginx代理详解..单点登录系统工程搭建_接口文档讲解 day11_单点登录系统实现_用户名回显_cookie跨域...

    单点登录源码

    ActiveMQ | 消息队列 | [http://activemq.apache.org/](http://activemq.apache.org/) JStorm | 实时流式计算框架 | [http://jstorm.io/](http://jstorm.io/) FastDFS | 分布式文件系统 | ...

    Spring in Action(第2版)中文版

    10.1.3在spring中安装activemq 10.2协同使用jms和spring 10.2.1处理冗长失控的jms代码 10.2.2使用jms模板 10.2.3转换消息 10.2.4将spring的网关支持类应用于jms 10.3创建消息驱动pojo 10.3.1创建消息监听器 ...

Global site tag (gtag.js) - Google Analytics