package com.muyu.breakdown.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
 * 绑定交换机与队列
 * */
@Configuration
public class RabbitMQConfig {

    // 1.生命注册fanout模式的交换机
    @Bean
    public FanoutExchange fanoutExchange(){
        //1.fanout模式的路由名称 2.是否持久化 3. 是否自动删除
        return new FanoutExchange("fanout",true,false);
    }
    // 2.生命队列 sms.fanout.queue email.fanout.queue,duanxin.fanout.queue
    @Bean
    public Queue duanxinQueue(){
        return new Queue("duanxin",true);
    }


    @Bean
    public Queue emailQueue(){
        return new Queue("email",false);
    }

    @Bean
    public Queue smsQueue(){
        return new Queue("sms",false);
    }

    // 3.完成绑定关系(队列和交换机完成绑定关系
    @Bean
    public Binding duanxinExchange(){
        return BindingBuilder.bind(duanxinQueue()).to(fanoutExchange());
    }


    @Bean
    public Binding emailExchange(){
        return BindingBuilder.bind(emailQueue()).to(fanoutExchange());
    }

    @Bean
    public Binding smsExchange(){
        return BindingBuilder.bind(smsQueue()).to(fanoutExchange());
    }

    // 4.生命注册fanout模式的交换机
}
