First step: Referencing the associated jar package
<dependency><groupid>org.springframework</groupid><artifactid>spring-jms</ artifactid></dependency><dependency><groupid>org.springframework</groupid>< Artifactid>spring-context-support</artifactid></dependency>
Step Two: Configure ACTIVEMQ Integration Spring
<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans" xmlns: context= "Http://www.springframework.org/schema/context" xmlns:p= "http://www.springframework.org/schema/p" xmlns: aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xmlns:tx= "Http://www.springframework.org/schema/tx" xmlns:xsi= " Http://www.w3.org/2001/XMLSchema-instance "xsi:schemalocation=" Http://www.springframework.org/schema/beans http ://www.springframework.org/schema/beans/spring-beans-4.2.xsdhttp://www.springframework.org/schema/context http ://www.springframework.org/schema/context/spring-context-4.2.xsdhttp://www.springframework.org/schema/aop http ://www.springframework.org/schema/aop/spring-aop-4.2.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/TX/http Www.springframework.org/schema/tx/spring-tx-4.2.xsdhttp://www.springframework.org/schema/util/HTTP Www.springframework.org/schema/util/spring-util-4.2.xsd "><!--can actually produce connection connectionfactory, by the corresponding JMS Service vendors provide--><bean Id= "Targetconnectionfactory" class= "org.apache.activemq.ActiveMQConnectionFactory" ><property name= " Brokerurl "value=" tcp://192.168.25.168:61616 "/></bean><!-- Spring is used to manage the real connectionfactory connectionfactory--><bean id= "ConnectionFactory" class= " Org.springframework.jms.connection.SingleConnectionFactory "><!--target connectionfactory corresponds to the real can generate JMS Connection connectionfactory--><property name= "targetconnectionfactory" ref= "Targetconnectionfactory"/> </bean><!--Configure the JMS tool class provided by producer--><!--Spring, which can send messages, receive, etc.--><bean id= "jmstemplate" class= " Org.springframework.jms.core.JmsTemplate "><!--this connectionfactory corresponds to the ConnectionFactory object that we defined spring provides. --><property name= "ConnectionFactory" ref= "ConnectionFactory"/></bean><!--This is the queue destination, point-to-point-- <bean id= "queuedestination" class= "Org.apache.activemq.command.ActiveMQQueue" ><constructor-arg>< Value>spring-queue</value></constructor-arg></bean><!--This is the theme destination, one-to-many--><bean id= "topicdestination" class= "Org.apache.activemq.command.ActiveMQTopic" ><constructor-arg value= "topic"/></bean></beans>
<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans" xmlns: context= "Http://www.springframework.org/schema/context" xmlns:p= "http://www.springframework.org/schema/p" xmlns: aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xmlns:tx= "Http://www.springframework.org/schema/tx" xmlns:xsi= " Http://www.w3.org/2001/XMLSchema-instance "xsi:schemalocation=" Http://www.springframework.org/schema/beans http ://www.springframework.org/schema/beans/spring-beans-4.2.xsdhttp://www.springframework.org/schema/context http ://www.springframework.org/schema/context/spring-context-4.2.xsdhttp://www.springframework.org/schema/aop http ://www.springframework.org/schema/aop/spring-aop-4.2.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/TX/http Www.springframework.org/schema/tx/spring-tx-4.2.xsdhttp://www.springframework.org/schema/util/HTTP Www.springframework.org/schema/util/spring-util-4.2.xsd "><!--can actually produce connection connectionfactory, by the corresponding JMS Service vendors provide--><bean Id= "Targetconnectionfactory" class= "org.apache.activemq.ActiveMQConnectionFactory" ><property name= " Brokerurl "value=" tcp://192.168.25.168:61616 "/></bean><!-- Spring is used to manage the real connectionfactory connectionfactory--><bean id= "ConnectionFactory" class= " Org.springframework.jms.connection.SingleConnectionFactory "><!--target connectionfactory corresponds to the real can generate JMS Connection connectionfactory--><property name= "targetconnectionfactory" ref= "Targetconnectionfactory"/> </bean><!--This is the queue destination, point-to-point--><bean id= "Queuedestination" class= " Org.apache.activemq.command.ActiveMQQueue "><constructor-arg><value>spring-queue</value> </constructor-arg></bean><!--This is the theme destination, one-to-many--><bean id= "topicdestination" class= " Org.apache.activemq.command.ActiveMQTopic "><constructor-arg value=" topic "/></bean><!--receive messages-- ><!--Configuration Listener--><bean id= "Mymessagelistener" class= "Cn.e3mall.search.listener.MyMessageListener"/≫<!--Message monitoring container--><bean class= "Org.springframework.jms.listener.DefaultMessageListenerContainer" >< Property Name= "ConnectionFactory" ref= "connectionfactory"/><property name= "destination" ref= " Queuedestination "/><property name=" MessageListener "ref=" Mymessagelistener "/></bean></beans >
ACTIVEMQ and Spring Integration