1. Configuration connectionfactory
ConnectionFactory, which is used to produce a JMS connection, provides us with a variety of connectionfactory which are: Singleconnectionfactory and Cachingconnectionfactory.
XML Configuration
<bean id= "cachingconnectionfactory" class= " org.springframework.jms.connection. cachingconnectionfactory"/>
But this doesn't create a JMS connection for us. Spring just provides the ability to manage connectionfactory. The actual production connection requires a JMS service provider to provide the ACTIVEMQ that we use so that the real creation or the Apache ACTIVEMQ provides
Real production connections
<bean id= "targetconnectionfactory" class= " Org.apache.activemq.ActiveMqconnectionfactory">
<property name= "Brokerurl" value= "${mq.brokerurl}" ></property>
<property name= "UserName" value= "${mq.username}" ></property>
<property name= "Password" value= "${mq.password}" ></property
</bean>
registered in spring managed by spring
<bean id= "Cachingconnectionfactory" class= "Org.springframework.jms.connection.CachingConnectionFactory"/>
<property name= "Targetconnectionfactory" ref= "Targetconnectionfactory" ></property>
<property name= "sessioncachesize" value= "></property>"
</bean>
2. Configure the Producer
The producer is responsible for producing messages and sending them to the JMS server. Implemented by the jmstemplate provided by spring,
Because sending a message needs to know where to send it, you need to specify connectionfactory.
the JMS tool class provided by spring can be used for message sending, receiving, etc.
<bean id= "Activemqjmstemplate" class= "Org.springframework.jms.core.JMSTemplate" >
<property name= "connectionfactory" ref = "Cachingconnectionfactory"/>
</bean>
and need to know where to send the destination so also specify defaultdestination there are two ways to specify a name (defaultdestinationname) or a specified bean ( Defaultdestination)
The configuration message destination is divided into two kinds of queue destinations (point-to-point) a point-to-multiple
Team column destination Point-to-point
<bean id= "queuedestination" class= "Org.apache.activemq.command.ActiveMQQueue" >
<constructor-arg>
<value>queue</value> / /constructor injection named queue
</constructor-arg>
</bean>
Theme Destinations , one -to-many
<bean id= "topicdestination" class= "Org.apache.activemq.command.ActiveMQTopic" >
<constructor-arg value= "topic"/> //constructor injection named topic
</bean>
3. Message sending Java
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/7C/0A/wKioL1bOnJHx4v_tAABqWszyRJw596.png "title=" 0]l% TSQGYQ]4_H9%C{CX (@2.png "alt=" Wkiol1bonjhx4v_taabqwszyrjw596.png "/>
4. Message Consumers
how consumers know that a message has arrived at the destination is implemented through spring for the message listener container Messagelistenercontainer. When the listener is assigned to the real listener to handle (messagelistener, sessionawaremessagelistener). There are three things you must know about the listener. One: Who listens to (MessageListener,sessionawaremessagelistener) Second, listens to WHO (queue destination) third, where to go to prison
Listen (connectionfactory)
Real listeners implement their own business logic processing
<bean id= "Consumersessionawaremessagelistener" class= " Com.fx.crm.webService.service.ConsumerSessionAwareMessageListener "></bean>
Java code
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7C/12/wKioL1bOo-OxemFwAAClW4SINvs467.png "title=" hhqu0t _7$]ev9x{q]b@h{k2.png "alt=" Wkiol1boo-oxemfwaaclw4sinvs467.png "/>
Configuration of the Spring monitoring container
<bean id= "Sessionawarelistenercontainer" class= " Org.springframework.jms.listener.DefaultMessageListenerContainer ">
<property name= "ConnectionFactory" ref= "Cachingconnectionfactory"/>
<property name= "Destination" ref= "Sessionawarequeue"/>
<property name= "MessageListener" ref= "Consumersessionawaremessagelistener"/>
</bean>
Documentation:
http://blog.csdn.net/haoxingfeng/article/details/9167895
This article is from the "7619052" blog, please be sure to keep this source http://7629052.blog.51cto.com/7619052/1744999
ACTIVEMQ and Spring Integration