Spring ActiveMQ ActiveMQ integration of configuration

1. dependence

<!-- ActiveMQ客户端完整jar包依赖 -->
<dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>activemq-all</artifactId>
    <version>5.9.0</version>
</dependency>

<-! Spring-JMS widget related jar package dependency ->

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-jms</artifactId>

<version>4.1.6.RELEASE</version>

</dependency>

2xml Configuration




    
    
    bean name="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
        <property name="connectionFactory">
            <bean class="org.apache.activemq.ActiveMQConnectionFactory">
                <property name="brokerURL" value="tcp://192.168.23.12:61616"/>
                <property name="userName" value="admin"/>
                <property name="password" value="admin"/>
            </bean>
        </property>
        <property name="maxConnections" value="20"></property>
    </bean>

    <!-- 2、spring整合activemq链接工厂 
        可以缓存session。
    -->
    <bean name="cachingConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
        <property name="targetConnectionFactory" ref="pooledConnectionFactory"></property>
        <property name="sessionCacheSize"value = ". 5" > </ Property > 
    </ the bean > 
    
    <-! . 3, the operation target message JmsTemplate Spring integration 
        using jmsTemplate can simplify the code, do not need to send the object to create a message. 
    -> 
    < the bean name = "JmsTemplate" class = "org.springframework.jms.core.JmsTemplate" > 
        < Property name = "The connectionFactory" REF = "cachingConnectionFactory" > </ Property > 
    </ the bean > 

    
    <-! . 4 , spring loaded listeners 
        acknowledge = "auto" 
            Indicates that the message get after, automatic queue default: support for session caching. 
    -> 
    <jms: listener-Container Acknowledge = "Auto" 
        Container-of the type = "default" 
        Where do you want-of the type = "Queue" 
        Connection-Factory's = "cachingConnectionFactory" > 
        ! <- Specifies the listener 
            destination = "order-mq" specify the listener is which queue 
            ref = "orderListener" Specifies the listener object using annotations when the name of the object class name is lowercase first letter 
         -> 
        < jms: listener where do you want = "the Order-MQ" ref = "orderListener" />     
    </ jms : listener-Container > 

</ Beans >

 

Guess you like

Origin www.cnblogs.com/heviny/p/11265821.html