Newer
Older
sink_mysql8.0 / src / main / resources / wellSensor / applicationContex-ActiveMQ.xml
zhout on 1 Jul 2020 3 KB 数据库配置文件修改
<?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:amq="http://activemq.apache.org/schema/core"
       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
        http://activemq.apache.org/schema/core
        http://activemq.apache.org/schema/core/activemq-core-5.14.5.xsd"
>
    <context:annotation-config/>
    <context:component-scan base-package="org.well.well"/>

    <amq:connectionFactory id="amqConnectionFactory"
                           brokerURL="${activemq_url}"
                           userName="${activemq_username}"
                           password="${activemq_password}"/>
    <!--&lt;!&ndash; 连接 activemq&ndash;&gt;-->
    <!--<amq:connectionFactory id="amqConnectionFactory" brokerURL="${activemq_url}" userName="${activemq_username}"-->
    <!--password="${activemq_password}"/>-->

    <!-- 这里可以采用连接池的方式连接PooledConnectionFactoryBean -->
    <bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
        <!-- 配置连接 -->
        <property name="targetConnectionFactory" ref="amqConnectionFactory"/>
        <!-- 会话的最大连接数 -->
        <property name="sessionCacheSize" value="100"/>
    </bean>

    <!-- 定义消息队列(Queue) -->
    <bean id="demoQueueDestination" class="org.apache.activemq.command.ActiveMQQueue">
        <!-- 设置消息队列的名字 -->
        <constructor-arg>
            <value>hjt.msg.queue</value>
        </constructor-arg>
    </bean>
    <!-- 配置JMS模板(Queue),Spring提供的JMS工具类,它发送、接收消息。 -->
    <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
        <property name="connectionFactory" ref="connectionFactory"/>
        <property name="defaultDestination" ref="demoQueueDestination"/>
        <property name="receiveTimeout" value="10000"/>
        <!-- true是topic,false是queue,默认是false,此处显示写出false -->
        <property name="pubSubDomain" value="false"/>
    </bean>

    <!-- 配置消息队列监听者(Queue) -->
    <bean id="queueMessageListener" class="org.well.well.activemq.QueueMessageListener"/>

    <!-- 显示注入消息监听容器(Queue),配置连接工厂,监听的目标是demoQueueDestination,监听器是上面定义的监听器 -->
    <bean id="queueListenerContainer"
          class="org.springframework.jms.listener.DefaultMessageListenerContainer">
        <property name="connectionFactory" ref="connectionFactory"/>
        <property name="destination" ref="demoQueueDestination"/>
        <property name="messageListener" ref="queueMessageListener"/>
    </bean>

</beans>