package com.fdkanfang.web.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 即时队列
 */

@Configuration
public class RabbitConfig {

    @Value("${verticle.queue}")
    public static  String VERTICAL_QUEUE_SRC;

    /** 垂直校验队列*/
    public static final String VERTICAL_QUEUE = "verticalQueue";

    /** 垂直校验交换机*/
    public static final String VERTICAL_EXCHANGE = "verticalExchange";

    /** 垂直校验交换机路由*/
    public static final String VERTICAL_QUEUE_ROUTING = "verticalQueueRouting";


    /** 生成模型队列*/
    public static final String PANO_QUEUE = "panoQueue";

    /** 生成模型交换机*/
    public static final String PANO_EXCHANGE = "panoExchange";

    /** 生成模型交换机路由*/
    public static final String PANO_QUEUE_ROUTING = "panoQueueRouting";


    /** 生成模型队列*/
    public static final String PANO_CALLBACK_QUEUE = "panoCallbackQueue";

    /** 生成模型交换机*/
    public static final String PANO_CALLBACK_EXCHANGE = "panoCallbackExchange";

    /** 生成模型交换机路由*/
    public static final String PANO_CALLBACK_QUEUE_ROUTING = "panoCallbackQueueRouting";


    /**
     * 创建队列
     */
    @Bean
    public Queue verticalQueue() {
        return new Queue(VERTICAL_QUEUE);
    }

    /**
     * 创建交换机
     */
    @Bean
    public Exchange verticalExchange(){
        return new DirectExchange(VERTICAL_EXCHANGE, true, false);
    }


    /**
     * 队列绑定交换机
     */
    @Bean
    public Binding verticalQueueExchange(Queue verticalQueue, Exchange verticalExchange){
        return BindingBuilder.bind(verticalQueue).to(verticalExchange).with(VERTICAL_QUEUE_ROUTING).noargs();
    }


    /**
     * 创建生成模型队列
     */
    @Bean
    public Queue panoQueue() {
        return new Queue(PANO_QUEUE);
    }

    /**
     * 创建生成模型交换机
     */
    @Bean
    public Exchange panoExchange(){
        return new DirectExchange(PANO_EXCHANGE, true, false);
    }


    /**
     * 生成模型队列绑定交换机
     */
    @Bean
    public Binding panoQueueExchange(Queue panoQueue, Exchange panoExchange){
        return BindingBuilder.bind(panoQueue).to(panoExchange).with(PANO_QUEUE_ROUTING).noargs();
    }


    /**
     * 创建生成模回调型队列
     */
    @Bean
    public Queue panoCallbackQueue() {
        return new Queue(PANO_CALLBACK_QUEUE);
    }

    /**
     * 创建生成模型回调交换机
     */
    @Bean
    public Exchange panoCallbackExchange(){
        return new DirectExchange(PANO_CALLBACK_EXCHANGE, true, false);
    }


    /**
     * 生成模型回调队列绑定交换机
     */
    @Bean
    public Binding panoCallbackQueueExchange(Queue panoCallbackQueue, Exchange panoCallbackExchange){
        return BindingBuilder.bind(panoCallbackQueue).to(panoCallbackExchange).with(PANO_CALLBACK_QUEUE_ROUTING).noargs();
    }
}
