ACTIVEMQ Spring Client

Source: Internet
Author: User

One, the relevant jar package

Activemq-pool, Activemq-broker, Activemq-client, Xbean-spring (embbed's broker use)


Second, Spring-activemq-provider.xml

<?xml version= "1.0" encoding= "UTF-8"?>
<beans xmlns= "Http://www.springframework.org/schema/beans"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:context= "Http://www.springframework.org/schema/context"
Xsi:schemalocation= "
Http://www.springframework.org/schema/beans
Http://www.springframework.org/schema/beans/spring-beans.xsd
Http://www.springframework.org/schema/context
Http://www.springframework.org/schema/context/spring-context.xsd
">

<!--ACTIVEMQ Connection factory--
<bean id= "Jmsfactory" class= "Org.apache.activemq.ActiveMQConnectionFactory" >
<property name= "Brokerurl" >
<value>tcp://localhost:61616</value>
</property>
<property name= "UserName" >
<value>admin</value>
</property>
<property name= "Password" >
<value>password</value>
</property>
</bean>

<!--connection Pool--
<bean id= "Pooledjmsfactory" class= "org.apache.activemq.pool.PooledConnectionFactory" destroy-method= "Stop" >
<property name= "ConnectionFactory" >
<ref local= "Jmsfactory"/>
</property>
</bean>

<!--consumption send and receive templates--
<bean id= "Jmstemplate" class= "Org.springframework.jms.core.JmsTemplate" >
<property name= "ConnectionFactory" >
<ref local= "Pooledjmsfactory"/>
</property>
</bean>

<!--destination:queue and topic--
<bean id= "Queuedest" class= "Org.apache.activemq.command.ActiveMQQueue" autowire= "constructor" >
<constructor-arg value= "Queue-test"/>
</bean>
<bean id= "Topicdest" class= "Org.apache.activemq.command.ActiveMQTopic" autowire= "constructor" >
<constructor-arg value= "Topic-test"/>
</bean>

<!--business Realization Class--
<bean id= "Springprovider" class= "Com.activemq.demo.SpringProvider" >
<property name= "Template" >
<ref local= "Jmstemplate"/>
</property>
<property name= "Destinations" >
<list>
<ref local= "Queuedest"/>
<ref local= "Topicdest"/>
</list>
</property>
</bean>

</beans>


Third, Spring-activemq-consumer.xml

<?xml version= "1.0" encoding= "UTF-8"?>
<beans xmlns= "Http://www.springframework.org/schema/beans"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:context= "Http://www.springframework.org/schema/context"
Xsi:schemalocation= "
Http://www.springframework.org/schema/beans
Http://www.springframework.org/schema/beans/spring-beans.xsd
Http://www.springframework.org/schema/context
Http://www.springframework.org/schema/context/spring-context.xsd
">

<!--ACTIVEMQ Connection factory--
<bean id= "Jmsfactory" class= "Org.apache.activemq.ActiveMQConnectionFactory" >
<property name= "Brokerurl" >
<value>tcp://localhost:61616</value>
</property>
<property name= "UserName" >
<value>admin</value>
</property>
<property name= "Password" >
<value>password</value>
</property>
</bean>

<!--connection Pool--
<bean id= "Pooledjmsfactory" class= "org.apache.activemq.pool.PooledConnectionFactory" destroy-method= "Stop" >
<property name= "ConnectionFactory" >
<ref local= "Jmsfactory"/>
</property>
</bean>

<!--consumption send and receive templates--
<bean id= "Jmstemplate" class= "Org.springframework.jms.core.JmsTemplate" >
<property name= "ConnectionFactory" >
<ref local= "Pooledjmsfactory"/>
</property>
</bean>

<!--destination:queue and topic--
<bean id= "Queuedest" class= "Org.apache.activemq.command.ActiveMQQueue" autowire= "constructor" >
<constructor-arg value= "Queue-test"/>
</bean>

<!--business Implementation listener--
<bean id= "Msglistener" class= "Com.activemq.demo.SpringMessageListener"/>

<!--consumer Integration listener--
<bean id= "Javaconsumer" class= "Org.springframework.jms.listener.DefaultMessageListenerContainer" >
<property name= "ConnectionFactory" ref= "Jmsfactory"/>
<property name= "Destination" ref= "Queuedest"/>
<property name= "MessageListener" ref= "Msglistener"/>
</bean>


</beans>


Iv. Related Business Realization class

 

{

@Override

{
System.err.println ("Already consumed data:" + msg);

}

}


V. Testing


{
Classpathxmlapplicationcontext context = new Classpathxmlapplicationcontext ("Spring-activemq-provider.xml");

Springprovider Springprovider = Context.getbean (Springprovider.class);

Springprovider.sendqueue ("This is the test");

}

{
New Classpathxmlapplicationcontext ("Spring-activemq-consumer.xml");

}


Reference Address:

Http://activemq.apache.org/spring-support.html

Http://docs.spring.io/spring/docs/2.5.x/reference/jms.html#jms-mdp


This article is from the "Traveler" blog, so be sure to keep this source http://881206524.blog.51cto.com/10315134/1928731

ACTIVEMQ Spring Client

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.