• RabbitMQ 死信队列 延时


    package com.hs.services.config;
    
    import java.util.HashMap;
    import java.util.Map;
    
    import org.springframework.amqp.core.Binding;
    import org.springframework.amqp.core.BindingBuilder;
    import org.springframework.amqp.core.DirectExchange;
    import org.springframework.amqp.core.Queue;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    
    /**
     * rabbitmq 配置
     * @author ZHANGYUKUN
     *
     */
    @Configuration
    public class RabbitMQConfig {
        
        //钱包交换机
        public static final String walletExchange  = "walletExchange";
        
        //红包交换机
        public static final String redpacketExchange  = "redpacketExchange";
        
        @Bean
        public DirectExchange walletExchange() {
            return new DirectExchange(RabbitMQConfig.walletExchange, true, false);
        }
        @Bean
        public DirectExchange redpacketExchange() {
            return new DirectExchange(RabbitMQConfig.redpacketExchange, true, false);
        }
        
        
        
        
        
        
        
    
        /**
         * 钱包
         */
        public static final String walletAmountChange = "walletAmountChange";
        public static final String walletAmountChangeDL = "walletAmountChangeDL";
        
        /**
         * 红包
         */
        public static final String redpacketChange = "redpacketChange";
        public static final String redpacketChangeDL = "redpacketChangeDL";
    
        
        /**
         * 钱包余额 相关
         * @return
         */
        @Bean
        public Queue walletAmountChange() {
            return new Queue( RabbitMQConfig.walletAmountChange );
        }
        @Bean
        public Queue walletAmountChangeDL() {
            Map<String, Object> arguments = new HashMap<>();
            arguments.put("x-dead-letter-exchange", RabbitMQConfig.walletExchange);
            arguments.put("x-dead-letter-routing-key", RabbitMQConfig.walletAmountChangeDL);
            return new Queue(RabbitMQConfig.walletAmountChangeDL, true, false, false, arguments);
        }
        @Bean
        public Binding  walletAmountChangeBind(Queue walletAmountChange ,DirectExchange walletExchange ) {
            return BindingBuilder.bind( walletAmountChange ).to( walletExchange ).with( RabbitMQConfig.walletAmountChange );
        }
        @Bean
        public Binding  walletAmountChangeBindDL(Queue walletAmountChangeDL ,DirectExchange walletExchange ) {
            return BindingBuilder.bind( walletAmountChangeDL ).to( walletExchange ).with( RabbitMQConfig.walletAmountChangeDL );
        }
        
        
        
        /**
         * 钱包余额 相关
         * @return
         */
        @Bean
        public Queue redpacketChange() {
            return new Queue( RabbitMQConfig.redpacketChange );
        }
        @Bean
        public Queue redpacketChangeDL() {
            Map<String, Object> arguments = new HashMap<>();
            arguments.put("x-dead-letter-exchange", RabbitMQConfig.redpacketExchange);
            arguments.put("x-dead-letter-routing-key", RabbitMQConfig.redpacketChangeDL);
            return new Queue(RabbitMQConfig.redpacketChangeDL, true, false, false, arguments);
        }
        @Bean
        public Binding  redpacketChangeBind(Queue redpacketChange ,DirectExchange redpacketExchange ) {
            return BindingBuilder.bind( redpacketChange ).to( redpacketExchange ).with( RabbitMQConfig.redpacketChange );
        }
        @Bean
        public Binding redpacketChangeBindDL(Queue redpacketChangeDL ,DirectExchange redpacketExchange ) {
            return BindingBuilder.bind( redpacketChangeDL ).to( redpacketExchange ).with( RabbitMQConfig.redpacketChangeDL );
        }
     
    
    }

    上述 ,配了 死信队列,如果 如果 发送到 死信里面的消息 如果 超时,就会被转交给 对应的  正常队列。 死信 的这个特点可以做延时消息。

  • 相关阅读:
    1091. Shortest Path in Binary Matrix (M)
    1342. Number of Steps to Reduce a Number to Zero (E)
    0242. Valid Anagram (E)
    京准为您提供选卫星时钟(NTP时钟服务器)技巧
    时统设备(NTP授时服务器)产品概述与介绍
    NTP母钟(NTP网络子钟)为医院提高办公效率
    基于NTP/SNTP的网络授时服务系统方案
    NTP子钟(GPS母钟)功能与调试安装配置
    GPS时间统一系统(时统设备)介绍与应用
    GPS子母钟系统(电子时钟系统)让医院信息化更有意义
  • 原文地址:https://www.cnblogs.com/cxygg/p/10607366.html
Copyright © 2020-2023  润新知