package com.pj.rabbitmq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;




/**
 * @Author Mechrevo
 * @Date 2023 08 25 12 21
 **/
@Configuration
public class RabbitmqConfig {
//
//
//    @Value("${spring.rabbitmq.host}")
//    private String host;
//
//    @Value("${spring.rabbitmq.port}")
//    private int port;
//
//    @Value("${spring.rabbitmq.username}")
//    private String username;
//
//    @Value("${spring.rabbitmq.password}")
//    private String password;
//
//    @Value("${spring.rabbitmq.virtual-host}")
//    private String virtualHost;



    /**
     * 发送时的mq队列
     * @return
     */
    @Bean
    public Queue testSend(){
        return new Queue(RabbitMQ.TEST_SEND_QUEUE,true);
    }

    /**
     * 接收时的mq队列
     * @return
     */
    @Bean
    public Queue testAccept(){
        return new Queue(RabbitMQ.TEST_ACCEPT_QUEUE,true);
    }

    /**
     * 交换机
     * @return
     */
    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange(RabbitMQ.MQ_DIRECT_EXCHANGE,true,false);
    }

    /**
     * 绑定
     * 发送
     */
    @Bean
    public Binding bindingSend(){
        return BindingBuilder.bind(testSend()).to(directExchange()).with(RabbitMQ.TEST_SEND_ROUTING_KEY);
    }

    /**
     * 绑定
     * 接收
     */
    @Bean
    public Binding bindingAccept(){
        return BindingBuilder.bind(testAccept()).to(directExchange()).with(RabbitMQ.TEST_ACCEPT_ROUTING_KEY);
    }

}
