消息队列MQ

rabbitMq可靠消息投递之交换机备份

本文主要是介绍rabbitMq可靠消息投递之交换机备份,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
   //备份队列
    @Bean("alternate_queue")
    public Queue alternate_queue() {
        return new Queue("alternate_queue", true);
    }


 //备份交换机
    @Bean("alternate_exchange")
    public TopicExchange alternate_exchange() {
        return new TopicExchange("alternate_exchange", true, false);
    }


 //备份队列
    @Bean("backBinding")
    public Binding backBinding(@Qualifier("alternate_queue") Queue third,@Qualifier("alternate_exchange")TopicExchange exchange) {
        return BindingBuilder.bind(third).to(exchange).with("#");//备份交换机是无条件的路由键
    }










    //给自己留一个备份交换机  alternate_exchange
    @Bean("firstExchange")
    public FanoutExchange firstExchange() {
        //声明交换机的时候指定备份交换机
        Map<String,Object> arguments=new HashMap<>();
        arguments.put("alternate-exchange","alternate_exchange");
        return new FanoutExchange("firstExchange", true, false,arguments);
    }


    @Bean("firstBinding")
    public Binding firstBinding(@Qualifier("first") Queue first,@Qualifier("firstExchange")FanoutExchange exchange) {
        return BindingBuilder.bind(first).to(exchange);
    }

    @Bean("first")
    public Queue first() {
        return new Queue("first", true);
    }

 

这篇关于rabbitMq可靠消息投递之交换机备份的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!