package com.usky.fire.service.config.rabbitmq;

import com.rabbitmq.client.AMQP;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
    //点对点
    //队列
    public String patrolEventQueue = "Patrol_QEvent";
    //交换机
    public String patrolEventExchange = "Patrol_EEvent";
    //路由
    public String patrolEventRoute = "Patrol_REvent";

    //注册一个队列
    @Bean
    public Queue patrolQueue(){
        return QueueBuilder.durable(patrolEventQueue).maxLength(100).build();    //启动的时候，它会根据这个名称先去查找有没有这个队列，如果有什么都不做，如果没有就创建一个新的
    }

    //注册交换机
    @Bean
    public DirectExchange patrolExchange(){
        return ExchangeBuilder.directExchange(patrolEventExchange).build();
    }

    //绑定交换机与队列关系
    @Bean
    public Binding bindingPatrolExchangeMessage(){
        return BindingBuilder.bind(patrolQueue()).to(patrolExchange()).with(patrolEventRoute);
    }

    //广播
    public String patrolFEventExchange = "Patrol_FEvent";

    @Bean
    public FanoutExchange patrolFExchange(){
        return new FanoutExchange(patrolFEventExchange,true,false);
    }


}

























