ACTIVEMQ instance 2--spring JMS Send Message

Source: Internet
Author: User
Tags message queue

Reference article: Http://my.oschina.net/xiaoxishan/blog/381209#OSC_h3_7

One, the steps refer to the reference document

Ii. newly-built projects

Third, supplementary

Xml

1<?xml version= "1.0" encoding= "UTF-8"?>2<web-app version= "3.0" xmlns= "Http://java.sun.com/xml/ns/javaee"3Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"4Xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee5http//java.sun.com/xml/ns/javaee/web-app_3_0.xsd ">6     7<display-name>activemq</display-name>8 9<!--the path to the spring applicationcontext configuration file, you can use wildcards for the following spring Context Loader-Ten<context-param> One<param-name>contextConfigLocation</param-name> A<param-value> - Classpath:applicationContext.xml -</param-value> the</context-param> -  -<!--Spring ApplicationContext-Loaded -<listener> +<listener-class>org.springframework.web.context.contextloaderlistener</listener-class> -</listener> +  A<!--Spring MVC Servlet--- at<servlet> -<servlet-name>dispatcher</servlet-name> -<servlet-class>com.alibaba.dubbo.remoting.http.servlet.dispatcherservlet</servlet-class> -<init-param> -<param-name>contextConfigLocation</param-name> -<param-value>classpath:DispatcherServlet.xml</param-value> in</init-param> -<load-on-startup>1</load-on-startup> to</servlet> +<servlet-mapping> -<servlet-name>dispatcher</servlet-name> the<url-pattern>/</url-pattern> *</servlet-mapping> $ Panax Notoginseng      -<welcome-file-list> the<welcome-file>index.html</welcome-file> +</welcome-file-list> A</web-app>
View Code

Applicationcontext.xml

1<?xml version= "1.0" encoding= "UTF-8"?>2<Beans3Xmlns= "Http://www.springframework.org/schema/beans"4Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"5xmlns:context= "Http://www.springframework.org/schema/context"6Xmlns:goldfish= "Http://www.fangdd.com/schema/goldfish"7xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans.xsd8http//Www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd9http//Www.fangdd.com/schema/goldfishhttp://www.fangdd.com/schema/goldfish/goldfish-1.0.0.xsd">Ten  One<context:annotation-config/> A        -<context:component-scan base- Package= "Com.zp.test" > -</context:component-scan> the        -  -<!--automatically registers beans with annotation and guarantees @required, @Autowired properties are injected-- -<context:component-scan base- Package= "com.activemqtest.*"/> +  -<!--Configuring the JMS Connection Factory-- +<bean id= "ConnectionFactory"class= "Org.apache.activemq.ActiveMQConnectionFactory" > A<property name= "Brokerurl" value= "Failover: (tcp://localhost:61616)"/> at</bean> -      -<!--define Message Queuing (queue)-- -<bean id= "Queuedestination"class= "Org.apache.activemq.command.ActiveMQQueue" > -<!--set the name of the message queue-- -<constructor-arg> in<value>queue1</value> -</constructor-arg> to</bean> +      -<!--Configure a JMS template (Queue), a spring-provided JMS tool class that sends and receives messages. - the<bean id= "Jmstemplate"class= "Org.springframework.jms.core.JmsTemplate" > *<property name= "ConnectionFactory" ref= "ConnectionFactory"/> $<property name= "defaultdestination" ref= "Queuedestination"/>Panax Notoginseng<property name= "ReceiveTimeout" value= "10000"/> -</bean> the      +<!--queue message producer-- A<bean id= "Producerservice"class= "Com.activemqtest.serviceImpl.ProducerServiceImpl" > the<property name= "Jmstemplate" ref= "Jmstemplate" ></property> +</bean> -  $<!--queue message consumer-- $<bean id= "Consumerservice"class= "Com.activemqtest.serviceImpl.ConsumerServiceImpl" > -<property name= "Jmstemplate" ref= "Jmstemplate" ></property> -</bean> the      -<!--define Message Queuing (queue), we listen to a new queue, queue2--Wuyi<bean id= "QueueDestination2"class= "Org.apache.activemq.command.ActiveMQQueue" > the<!--set the name of the message queue-- -<constructor-arg> Wu<value>queue2</value> -</constructor-arg> About</bean> $      -<!--Configure the Message Queue Listener (queue), given below the code, there is only one OnMessage method-- -<bean id= "Queuemessagelistener"class= "Com.activemqtest.serviceImpl.QueueMessageListener"/> -      A<!--message listening container (queue), configure the connection factory, listen on the queue is queue2, listener is the listener defined above-- +<bean id= "Jmscontainer" the         class= "Org.springframework.jms.listener.DefaultMessageListenerContainer" > -<property name= "ConnectionFactory" ref= "ConnectionFactory"/> $<property name= "Destination" ref= "QueueDestination2"/> the<property name= "MessageListener" ref= "Queuemessagelistener"/> the</bean> the<!--defining message topics (TOPIC)-- the<bean id= "Topicdestination"class= "Org.apache.activemq.command.ActiveMQTopic" > -<constructor-arg> in<value>JY_topic</value> the</constructor-arg> the</bean> About<!--Configuring the JMS template (Topic), pubsubdomain= "true"- the<bean id= "Topicjmstemplate"class= "Org.springframework.jms.core.JmsTemplate" > the<property name= "ConnectionFactory" ref= "ConnectionFactory"/> the<property name= "defaultdestination" ref= "Topicdestination"/> +<property name= "Pubsubdomain" value= "true"/> -<property name= "ReceiveTimeout" value= "10000"/> the</bean>Bayi<!--topic Message Publisher-- the<bean id= "Topicprovider"class= "Com.activemqtest.serviceImpl.TopicProvider" > the<property name= "Topicjmstemplate" ref= "Topicjmstemplate" ></property> -</bean> -<!--message subject listener and Subject listener container can be configured with multiple subscribers-- the<!--message subject Listener (Topic)-- the<bean id= "Topicmessagelistener"class= "Com.activemqtest.serviceImpl.TopicMessageListener"/> the<!--subject monitoring container (Topic)-- the<bean id= "Topicjmscontainer" -         class= "Org.springframework.jms.listener.DefaultMessageListenerContainer" > the<property name= "ConnectionFactory" ref= "ConnectionFactory"/> the<property name= "Destination" ref= "Topicdestination"/> the<property name= "MessageListener" ref= "Topicmessagelistener"/>94</bean> the      the</beans>
View Code

Dispactcherservlet.xml

1<?xml version= "1.0" encoding= "UTF-8"?>2<beans xmlns= "Http://www.springframework.org/schema/beans"3Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"4xmlns:context= "Http://www.springframework.org/schema/context"5Xmlns:mvc= "Http://www.springframework.org/schema/mvc"6xsi:schemalocation= "Http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd7http//Www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-4.0.xsd8http//Www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.0.xsd">9     Ten<context:annotation-config/> One<context:component-scan base- Package= "Com.zp.test.controller" > A<context:include-filter type= "Annotation" expression= "Org.springframework.stereotype.Controller"/> -</context:component-scan> -</beans>
View Code

Iv. Results of operation

Because it runs two times, so it's even.

V. Problems encountered

Problem: Java.lang.IllegalStateException:Failed to load ApplicationContext

Reason: Because the package in the ApplicationContext does not correspond to the actual package, or there is no annotation to import the corresponding variable

ACTIVEMQ instance 2--spring JMS Send Message

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.