码迷,mamicode.com
首页 > 其他好文 > 详细

RabbitMQ通过DLX实现消息延迟接收

时间:2019-10-30 13:12:03      阅读:82      评论:0      收藏:0      [点我收藏+]

标签:apu   示例   tcl   work   amqp   json   template   延迟   confirm   

1. 创建队列WorkQueue,并把WorkQueue跟exchangeWork绑定;
2. 创建队列DLXQueue,并把DLXQueue跟exchangeDLX绑定;
a. 设置DLXQueue队列参数:
x-dead-letter-exchange 为DLXQueue
x-message-ttl 5000 单位毫秒
3. 将设置WorkQueue和DLXQueue两个exchange路由key都为DLXQueue(默认)
4. 设置exchangeDLX绑定exchangeWork,路由key为DLXQueue。

研华
spring 配置示例:
<?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"
xmlns:task="http://www.springframework.org/schema/task"
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/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.1.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
工控机
<!-- 定义rabbitmq连接工厂,生产环境使用集群配置,支持failover -->

<rabbit:connection-factory id="connectionFactory" publisher-confirms="true" addresses="${rabbitmq.host}" />

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

<bean id="jsonMessageConverter" class="org.springframework.amqp.support.converter.JsonMessageConverter">
<property name="classMapper">
<bean class="org.springframework.amqp.support.converter.DefaultClassMapper"/>
</property>
</bean>

<rabbit:template id="amqpTemplate" connection-factory="connectionFactory" message-converter="jsonMessageConverter"/>

RabbitMQ通过DLX实现消息延迟接收

标签:apu   示例   tcl   work   amqp   json   template   延迟   confirm   

原文地址:https://www.cnblogs.com/j950523/p/11764177.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!