RabbitMQ项目使用配置

本文详细介绍了RabbitMQ的生产者和消费者配置,包括Fanout、Direct和Topic三种Exchange模式。此外,还讲解了RabbitMQ的消息确认机制、延迟队列的实现方法,如TTL和Dead Letter Exchanges(DLX),以及如何设置队列和消息的TTL,以及DLX的配置示例。
摘要由CSDN通过智能技术生成

生产者配置:

<?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: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/rabbit
          http://www.springframework.org/schema/rabbit/spring-rabbit.xsd">


   <rabbit:connection-factory id="connectionFactory"
host="10.153.25.15" username="insurance" password="insurance" port="5672" />

   <rabbit:admin connection-factory="connectionFactory" />

   <rabbit:queue id="queue_insurance" durable="true" auto-delete="false"
exclusive="false" name="queue_insurance">正常队列当中指向死信
      <rabbit:queue-arguments>
         <entry key="x-message-ttl">设置超时
            <value type="java.lang.Long">30000</value>
         </entry>
         <entry key="x-dead-letter-exchange">指定交换机
            <value type="java.lang.String">alter</value>
         </entry>
      </rabbit:queue-arguments>
   </rabbit:queue>

   <rabbit:queue id="alter_queue" durable="true" auto-delete="false" exclusive="false" name="alter_queue"/>死信队列

   <rabbit:direct-exchange name="alter"
durable="true" auto-delete="false" id="alter">死信交换机
      <rabbit:bindings>
         <rabbit:binding queue="alter_queue" key="queue_key_insurance"/>
      </rabbit:bindings>
   </rabbit:direct-exchange>
   <rabbit:direct-exchange name="exchange_insurance"
durable="true" auto-delete="false" id="exchange_insurance">正常交换机
      <rabbit:bindings>
         <rabbit:binding queue="queue_insurance" key="queue_key_insurance" />
      </rabbit:bindings>
   </rabbit:direct-exchange>

<!-- (5)客户端投递消息到exchange。 -->
<rabbit:template id="amqpTemplate" exchange="exchange_insurance"
connection-factory="connectionFactory" />
</beans>
  • 5
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值