//备份队列 @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); }