package com.sw.mes.config.rabbit;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

/**
 * Broker:它提供一种传输服务,它的角色就是维护一条从生产者到消费者的路线，保证数据能按照指定的方式进行传输,
 * Exchange：消息交换机,它指定消息按什么规则,路由到哪个队列。 Queue:消息的载体,每个消息都会被投到一个或多个队列。
 * <p>
 * Binding:绑定，它的作用就是把exchange和queue按照路由规则绑定起来.
 * <p>
 * Routing Key:路由关键字,
 * <p>
 * exchange根据这个关键字进行消息投递。 vhost:虚拟主机,一个broker里可以有多个vhost，用作不同用户的权限分离。
 * <p>
 * Producer:消息生产者,就是投递消息的程序. Consumer:消息消费者,就是接受消息的程序.
 * Channel:消息通道,在客户端的每个连接里,可建立多个channel.
 */

//@Configuration
public class RabbitConfig {
    public static final String INSPECT_DATA = "inspectData";
    public static final String INSPECT_DATA_QUEUE = "inspectDataQueue";
    public static final String INSPECT_DATA_EXCHANGE = "inspectDataExchange";

    /**
     * 圆棒检验数据变动队列
     *
     * @return Queue
     */
    //@Bean(INSPECT_DATA_QUEUE)
    public Queue inspectDataQueue() {
        return new Queue(INSPECT_DATA_QUEUE, true);
    }

    //@Bean(INSPECT_DATA_EXCHANGE)
    public DirectExchange squareExternalDataExchange() {
        return new DirectExchange(INSPECT_DATA_EXCHANGE);
    }

    //@Bean
    public Binding squareExternalDataBinding(@Qualifier(INSPECT_DATA_QUEUE) Queue queue, @Qualifier(INSPECT_DATA_EXCHANGE) DirectExchange directExchange) {
        return BindingBuilder.bind(queue).to(directExchange).with(INSPECT_DATA);
    }


    // spc获取检验数据 ------------------
    public static final String QUEUE_SPC_SIX_YB_PRODUCT_INSPECT = "QUEUE_SPC_SIX_YB_PRODUCT_INSPECT";
    public static final String EXCHANGE_SPC_SIX_YB_PRODUCT_INSPECT = "exchange_spc_six_yb_product_Inspect";
    public static final String KEY_SIX_SPC_PRODUCT_INSPECT = "KEY_SIX_YB_SPC_PRODUCT_INSPECT";

    //@Bean
    public Queue queueProductSpc() {
        return new Queue(QUEUE_SPC_SIX_YB_PRODUCT_INSPECT, true);
    }
    //@Bean()
    public DirectExchange defaultExchangeProductSpc() {
        return new DirectExchange(EXCHANGE_SPC_SIX_YB_PRODUCT_INSPECT);
    }
    //@Bean
    public Binding bindingExchangeMEAS() {
        return BindingBuilder.bind(queueProductSpc()).to(defaultExchangeProductSpc()).with(KEY_SIX_SPC_PRODUCT_INSPECT);
    }
    //  spc获取检验数据 -----------------

    // spc获取长晶棒数据 ------------------
    public static final String QUEUE_SPC_LONG_CRYSTAL = "QUEUE_SPC_SIX_YB_PRODUCT_INSPECT";
    public static final String LONG_CRYSTAL_EXCHANGE = "longCrystalExchange";
    public static final String LONG_CRYSTAL = "longCrystal";

    //@Bean
    public Queue queueProductData() {
        return new Queue(QUEUE_SPC_LONG_CRYSTAL, true);
    }
    //@Bean()
    public DirectExchange defaultExchangeProductData() {
        return new DirectExchange(LONG_CRYSTAL_EXCHANGE);
    }
    //@Bean
    public Binding bindingExchangeData() {
        return BindingBuilder.bind(queueProductSpc()).to(defaultExchangeProductSpc()).with(LONG_CRYSTAL);
    }
    //  spc获取长晶棒数据 -----------------
}
