zoukankan      html  css  js  c++  java
  • Spring与RabbitMQ整合 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"
           xmlns:rabbit="http://www.springframework.org/schema/rabbit"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd
           http://www.springframework.org/schema/context
           https://www.springframework.org/schema/context/spring-context.xsd
           http://www.springframework.org/schema/rabbit
           http://www.springframework.org/schema/rabbit/spring-rabbit.xsd">
        <!--加载配置文件-->
        <context:property-placeholder location="classpath:rabbitmq.properties"/>
    	<context:component-scan base-package="com.landiss.rabbit.listener" />
    	
        <!-- 定义rabbitmq connectionFactory -->
        <rabbit:connection-factory id="connectionFactory" host="${rabbitmq.host}"
                                   port="${rabbitmq.port}"
                                   username="${rabbitmq.username}"
                                   password="${rabbitmq.password}"
                                   virtual-host="${rabbitmq.virtual-host}"
                                   publisher-confirms="true"
                                   publisher-returns="true"/>
        <!--定义管理交换机、队列-->
        <rabbit:admin connection-factory="connectionFactory"/>
    
        <!--定义rabbitTemplate对象操作可以在代码中方便发送消息-->
        <rabbit:template id="rabbitTemplate" connection-factory="connectionFactory"/>
    
        <!--消息可靠性投递(生产端)-->
        <!--durable持久化设置,true表示持久,false表示RabbitMQ服务重启后Queue、Exchange丢失-->
        <rabbit:queue id="queueConfirm" name="queue_confirm" durable="false">
        	<rabbit:queue-arguments>
        		<entry key="x-max-length" value="3" value-type="java.lang.Integer"></entry>
        	</rabbit:queue-arguments>
        </rabbit:queue>
        
        <rabbit:direct-exchange name="direct_exchange_confirm" durable="false">
        	<rabbit:bindings>
        		<rabbit:binding queue="queueConfirm" key="route.producer.confirm"></rabbit:binding>
        	</rabbit:bindings>
        </rabbit:direct-exchange>
        
        <!-- 主题模式 -->
        <rabbit:queue id="queueTopic1" name="queue_topic1" durable="false"></rabbit:queue>
        <rabbit:queue id="queueTopic2" name="queue_topic2" durable="false"></rabbit:queue>
        
        <rabbit:topic-exchange name="topic_exchange" durable="false">
        	<rabbit:bindings>
        		<rabbit:binding pattern="route.one.#" queue="queueTopic1"></rabbit:binding>
        		<rabbit:binding pattern="route.two.*" queue="queueTopic2"></rabbit:binding>
        		<rabbit:binding pattern="route.#" queue="queueConfirm"></rabbit:binding>
        	</rabbit:bindings>
        </rabbit:topic-exchange>
        
        <context:component-scan base-package="com.landiss.rabbit.listener" />
        
        <!--定义监听器容器 acknowledge="manual":手动签收 prefetch="1":每次抓取多少条消息  -->
        <rabbit:listener-container connection-factory="connectionFactory" acknowledge="manual" prefetch="2">
    	    <rabbit:listener ref="confirmListener" queue-names="queue_confirm"></rabbit:listener>
        </rabbit:listener-container>
    </beans>
    
    —转载请注明出处
  • 相关阅读:
    第10章 指针(二) 首地址指针
    第10章 指针(五) 使用地址指针的引用
    第10章 指针(六) 指针小结
    C语言中的类模拟(C++编程思想)
    经典SQL语句大全
    C#ADO.NET操作数据代码汇总
    C#日期格式化
    第10章 指针(四) 地址簿指针变量
    数据库设计中的14个技巧
    第9章 预处理命令
  • 原文地址:https://www.cnblogs.com/landiss/p/14578473.html
Copyright © 2011-2022 走看看