ITPub博客

首页 > 数据治理 > 数据治理 > RabbitMQ通过DLX实现消息延迟接收

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

原创 数据治理 作者:coffee1995 时间:2019-10-16 17:06:37 0 删除 编辑

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"/>


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69951032/viewspace-2660246/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2019-10-16

  • 博文量
    1
  • 访问量
    747