package com.muyu.breakdown.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 绑定交换机与队列
 * */
@Configuration
public class RabbitMQTopicConfig {
    /**
     * 与fanout发布订阅模式不同的是 Direct 需要在Binding规定对应的 路由名称
     * */
    // 1.生命注册fanout模式的交换机
    @Bean
    public TopicExchange topicExchange(){
        //1.fanout模式的路由名称 2.是否持久化 3. 是否自动删除
        return new TopicExchange("topic",true,false);
    }
    // 2.生命队列 sms.fanout.queue email.fanout.queue,duanxin.fanout.queue
    @Bean
    public Queue topicduanxinQueue(){
        return new Queue("topicduanxin.test.one",true);
    }


    @Bean
    public Queue topicemailQueue(){
        return new Queue("topicemail.test.two",false);
    }

    @Bean
    public Queue topicsmsQueue(){
        return new Queue("topicsms.test.three",false);
    }

    // 3.完成绑定关系(队列和交换机完成绑定关系
    @Bean
    public Binding topicduanxinExchange(){
        return BindingBuilder.bind(topicduanxinQueue()).to(topicExchange()).with("topic.#");
    }


    @Bean
    public Binding topicemailExchange(){
        return BindingBuilder.bind(topicemailQueue()).to(topicExchange()).with("topic.*");
    }

    @Bean
    public Binding topicsmsExchange(){
        return BindingBuilder.bind(topicsmsQueue()).to(topicExchange()).with("topic.test.#");
    }

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