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