package com.persagy.dmp.rwd.digital.config;

import com.persagy.dmp.basic.constant.DigitalMessageConstant;
import lombok.extern.slf4j.Slf4j;
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;

/**
 * 项目变更消息配置
 * @author Charlie Yu
 * @date 2021-06-25
 */
@Slf4j
@Configuration
public class DigitalRabbitConfig {

    /** 项目消息 - Exchange */
    public static final String PROJECT_EXCHANGE = "saas.common.topic";
    /** 项目消息 - Queue */
    public static final String PROJECT_QUEUE = "bdtp.project.saas.queue";
    /** 项目消息 - RoutingKey */
    public static final String PROJECT_ROUTING_KEY = "saas.common.bdtp.project";

    @Bean
    public TopicExchange projectExchange() {
        return new TopicExchange(PROJECT_EXCHANGE);
    }

    @Bean
    public Queue projectQueue(){
        return new Queue(PROJECT_QUEUE);
    }

    @Bean
    public Binding projectBinding() {
        return BindingBuilder.bind(projectQueue()).to(projectExchange()).with(PROJECT_ROUTING_KEY);
    }

    @Bean
    public TopicExchange bdtpDigitalExchange() {
        return new TopicExchange(DigitalMessageConstant.MESSAGE_EXCHANGE);
    }

    @Bean
    public Queue bdtpDigitalQueue(){
        return new Queue(DigitalMessageConstant.MESSAGE_QUEUE);
    }

    @Bean
    public Binding bdtpDigitalBinding() {
        return BindingBuilder.bind(bdtpDigitalQueue()).to(bdtpDigitalExchange()).with(DigitalMessageConstant.MESSAGE_ROUTING);
    }
}
