<?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>