`
aslijiasheng
  • 浏览: 58394 次
  • 性别: 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

    在IT行业中,SpringMVC和JMS(Java Message Service)是两种非常重要的技术,而ActiveMQ则是实现JMS规范的开源消息代理。本项目结合这三者,提供了一个整合的Demo,旨在帮助开发者理解如何在SpringMVC应用中集成JMS...

    springmvc+dubbo/zookeeper+activemq+redis+mybatis+druid

    【标题】"springmvc+dubbo/zookeeper+activemq+redis+mybatis+druid" 涵盖了多个在企业级Java应用开发中的核心技术,它们共同构建了一个高可用、高性能的服务架构。以下是对这些技术的详细解释: 1. **SpringMVC**...

    spring+springmvc+mybatis+mongodb+ActiveMQ+CXF

    "spring+springmvc+mybatis+mongodb+ActiveMQ+CXF"就是一个典型的技术栈,它涵盖了后端开发、数据库管理、消息队列以及服务接口等多个关键领域。下面我们将详细探讨这些技术及其相互作用。 首先,Spring框架是Java...

    springMvc+spring+activeMq+mybaits

    在IT行业中,构建高效、可扩展的Web应用是至关重要的,而"springMvc+spring+activeMq+mybaits"这个项目组合提供了一个强大的框架基础。本文将深入探讨这四个关键技术及其相互间的协同工作。 首先,Spring MVC是...

    Springmvc+JPA(Hibernate4)+redis+activemq

    综上所述,"Springmvc+JPA(Hibernate4)+redis+activemq"的组合为开发者提供了一套强大、全面的工具集,可用于构建高度可扩展、高性能的现代Web应用。通过熟练掌握这些技术,开发者能够构建出更加健壮和灵活的应用...

    SpringMVC+Hibernate+ActiveMQ+spider

    这个项目结合了SpringMVC、Hibernate、ActiveMQ以及爬虫技术,它们各自扮演着关键角色。 首先,SpringMVC是Spring框架的一部分,用于构建Web应用程序。它采用Model-View-Controller(MVC)设计模式,将业务逻辑、...

    springMVC+activeMQ例子

    ActiveMQ是Apache软件基金会开发的消息中间件,支持JMS(Java消息服务)标准。它允许应用程序之间发送和接收消息,提供可靠的消息传输,即使在部分网络故障或服务器宕机的情况下也能保持数据的完整性。ActiveMQ支持...

    SpringMvc+Eclipselink+JPA+ActiveMQ+MySQL在线聊天

    在本项目中,"SpringMvc+Eclipselink+JPA+ActiveMQ+MySQL在线聊天" 实现了一个基于Web的即时通讯系统,模仿了微信的聊天功能。让我们逐一解析这个项目所涉及的关键技术: 1. **Spring MVC**: - Spring MVC是...

    activeMQ+spring+springmvc整合示例

    这个"activeMQ+spring+springmvc整合示例"旨在帮助开发者理解如何将这三者结合,以实现消息队列(Message Queue)的功能,提高系统的异步处理能力和负载均衡。以下是关于这一整合的详细知识讲解: 1. **ActiveMQ**:...

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

    SpringMvc、Redis、ActiveMQ是三个在IT领域中广泛应用的技术组件,它们分别在Web开发、数据缓存和消息传递方面发挥着重要作用。本教程将详细解释如何利用这些技术实现一个功能完备的消息发布订阅系统。 首先,...

    springMVC activemq简单聊天室

    1. 用户A在聊天室发送一条消息,SpringMVC控制器接收到请求后,将消息封装为JMS消息并发送到ActiveMQ的特定主题或队列。 2. ActiveMQ接收到消息后,将其存储在内存或磁盘中,并通知所有订阅了该主题的客户端有新消息...

    基于web的农业温湿度监控系统,SpringMVC+Spring+MyBatis+WebSocket+ActiveMQ.zip

    5. **ActiveMQ**:ActiveMQ是Apache的一个开源消息中间件,实现了多种消息协议,如JMS(Java Message Service)。在这个系统中,ActiveMQ可能被用来处理大量并发的温湿度数据,通过消息队列进行数据缓冲,保证数据的...

    SpringBoot+ActiveMq+MQTT实现消息的发送和接收

    接下来是ActiveMQ,它是Apache软件基金会的一个开源项目,是基于Java Message Service(JMS)规范的消息中间件。ActiveMQ可以存储和转发各种消息类型,包括文本、对象、文件以及流数据。在SpringBoot中集成ActiveMQ...

    ActiveMq+SpringMVC实现邮件异步发送

    为了实现这一功能,开发者需要在SpringMVC配置中添加ActiveMQ的相关配置,包括JMS模板和消息生产者的定义。同时,还需要编写一个邮件服务类,该类使用JMS模板发送消息到队列。而在消费者端,需要监听这个队列,接收...

    JMS+ActiveMQ+Spring 完整样例代码

    **JMS+ActiveMQ+Spring 完整样例代码详解** 在Java世界中,消息队列(Message Queue,简称MQ)是一种重要的中间件技术,它允许应用程序之间通过异步通信来解耦系统组件。Java消息服务(Java Message Service,简称...

    springMVC+activityMq

    在IT行业中,SpringMVC和ActiveMQ是两个非常重要的组件,它们分别负责Web应用程序的控制层和消息中间件。本文将深入探讨如何将SpringMVC与ActiveMQ集成,以及利用ActiveMQ实现Queue和Topic这两种消息模型。 首先,...

    spring,mybatis,hibernate,activemq,redis,dubbo的集成

    ActiveMQ 是Apache出品的一款消息中间件,基于Java消息服务(JMS)。它允许应用程序之间通过异步消息传递进行通信,提高系统的可扩展性和解耦度。在微服务架构中,ActiveMQ常被用于服务间的通讯。 5. **Redis**: ...

    JMS+activeMQ消息中间件

    **ActiveMQ**是Apache软件基金会开发的一款开源消息代理,它实现了JMS规范,为应用程序提供了一个中间件,允许应用程序之间进行异步的消息通信。ActiveMQ支持多种协议,如OpenWire、AMQP、STOMP、MQTT等,适用于多种...

    SpringMVC-activeMQ整合

    在IT行业中,SpringMVC和ActiveMQ是两个非常重要的组件,它们分别负责Web应用程序的控制层和消息中间件。SpringMVC是Spring框架的一部分,它提供了模型-视图-控制器(MVC)的设计模式,使得Java Web开发变得更加简洁...

    springmvc+activedMQ

    ActiveMQ 是Apache软件基金会开源的一款消息中间件,它实现了多种消息协议,如JMS(Java Message Service)、AMQP(Advanced Message Queuing Protocol)等。消息中间件的主要作用是解耦应用程序,使得发送方和接收...

Global site tag (gtag.js) - Google Analytics