package com.huimv.eartag.config;

import com.huimv.eartag.utils.Const;
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;

/**
 * @Project : huimv.shiwan
 * @Package : com.huimv.biosafety.uface.controller
 * @Description : TODO
 * @Version : 1.0
 * @Author : ZhuoNing
 * @Create : 2020-12-25
 **/
@Configuration
public class TopicRabbitMQConfig {
    //原始数据队列
    @Bean
    public Queue askDeviceQueue() {
        return new Queue(Const.QUEUE_ASK_DEVICE);
    }
    @Bean
    public Queue askEartagQueue() {
        return new Queue(Const.QUEUE_ASK_EARTAG);
    }
    //心跳
    @Bean
    public Queue heartbeatQueue() {
        return new Queue(Const.QUEUE_DEVICE_HEARTBEAT);
    }

    //采集器温度
    @Bean
    public Queue deviceTempQueue() {
        return new Queue(Const.QUEUE_DEVICE_TEMP);
    }
    //耳标数据
    @Bean
    public Queue eartagQueue() {
        return new Queue(Const.QUEUE_EARTAG);
    }


    //原始交换机
    @Bean
    TopicExchange askDeviceExchange() {
        return new TopicExchange(Const.EXCHANGE_ASK_DEVICE);
    }
    @Bean
    TopicExchange askEartagExchange() {
        return new TopicExchange(Const.EXCHANGE_ASK_EARTAG);
    }
    //采集器设备交换机
    TopicExchange deviceExchange() {
        return new TopicExchange(Const.EXCHANGE_DEVICE);
    }

    //耳标交换机
//    @Bean
    TopicExchange eartagExchange() {
        return new TopicExchange(Const.EXCHANGE_EARTAG);
    }


    //绑定关系
    @Bean
    Binding bindingDeviceExchangeMessage() {
        return BindingBuilder.bind(askDeviceQueue()).to(askDeviceExchange()).with(Const.ROUTING_KEY_ASK_DEVICE);
    }
    @Bean
    Binding bindingAskEartagExchangeMessage() {
        return BindingBuilder.bind(askEartagQueue()).to(askEartagExchange()).with(Const.ROUTING_KEY_ASK_EARTAG);
    }
    //设备交换机、心跳队列、心跳路由键绑定
    @Bean
    Binding bindingHeartbeatExchangeMessage() {
        return BindingBuilder.bind(heartbeatQueue()).to(deviceExchange()).with(Const.ROUTING_KEY_DEVICE_HEARTBEAT);
    }

    //设备交换机、设备环境温度队列、设备环境路由键绑定
    @Bean
    Binding bindingDeviceTempExchangeMessage() {
        return BindingBuilder.bind(deviceTempQueue()).to(deviceExchange()).with(Const.ROUTING_KEY_DEVICE_TEMP);
    }
    //耳标交换机、耳标队列、耳标路由键绑定
    @Bean
    Binding bindingEartagExchangeMessage() {
        return BindingBuilder.bind(eartagQueue()).to(eartagExchange()).with(Const.ROUTING_KEY_EARTAG);
    }

    // ============================= 设备绑定队列 ============================= //
    @Bean
    public Queue syncDeviceRegisterQueue() {
        return new Queue(Const.QUEUE_SYNC_DEVICE_REGISTER);
    }
    @Bean
    TopicExchange syncDeviceRegisterExchange() {
        return new TopicExchange(Const.EXCHANGE_SYNC_DEVICE_REGISTER);
    }
    @Bean
    Binding bindingDeviceRegisterExchangeMessage() {
        return BindingBuilder.bind(syncDeviceRegisterQueue()).to(syncDeviceRegisterExchange()).with(Const.ROUTING_KEY_SYNC_DEVICE_REGISTER);
    }

    // =============================耳标绑定队列 ============================= //
    @Bean
    public Queue syncEartagRegisterQueue() {
        return new Queue(Const.QUEUE_SYNC_EARTAG_REGISTER);
    }
    @Bean
    TopicExchange syncEartagRegisterExchange() {
        return new TopicExchange(Const.EXCHANGE_SYNC_EARTAG_REGISTER);
    }
    @Bean
    Binding bindingEartagRegisterExchangeMessage() {
        return BindingBuilder.bind(syncEartagRegisterQueue()).to(syncEartagRegisterExchange()).with(Const.ROUTING_KEY_SYNC_EARTAG_REGISTER);
    }

    // ============================= 同步设备总数-绑定队列 ============================= //
    @Bean
    public Queue syncDeviceTotalQueue() {
        return new Queue(Const.QUEUE_SYNC_DEVICE_TOTAL);
    }
    @Bean
    TopicExchange syncDeviceTotalExchange() {
        return new TopicExchange(Const.EXCHANGE_SYNC_DEVICE_TOTAL);
    }
    @Bean
    Binding bindingDeviceTotalExchangeMessage() {
        return BindingBuilder.bind(syncDeviceTotalQueue()).to(syncDeviceTotalExchange()).with(Const.ROUTING_KEY_SYNC_DEVICE_TOTAL);
    }

}
