zoukankan      html  css  js  c++  java
  • 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 );
        }
     
    
    }

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

  • 相关阅读:
    2019春总结
    2019春第一周编程总结
    第十二周
    2019春第七周编程总结
    2019春第四周作业
    人生路上对我影响最大的三位老师
    第五周课程总结&试验报告(三)
    第四周课程总结&试验报告(二)
    第三周课程总结&实验报告一
    第二周java学习总结
  • 原文地址:https://www.cnblogs.com/cxygg/p/10607366.html
Copyright © 2011-2022 走看看