package com.pannk.config;

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.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.pannk.cons.Constant.*;

/**
 * 默认模式-直连模式
 * Created by wolf on 20-11-17.
 */
@Configuration
public class DirectRabbitMQConfig {


    @Bean
    public Queue testDirectQueue() {
        return new Queue(DIRECT_QUEUE);
    }

    /**
     * 声明一个Direct exchange
     * 在发送消息时候就需要指定exchange
     * 不指定exchange时，默认使用的是direct exchange，而且routingKey与queue名一致
     *
     * @return
     */
//    @Bean
    public DirectExchange testDirectExchange() {
        return new DirectExchange(DIRECT_EXCHANGE);
    }

    //    @Bean
    public Binding bindingDirect() {
        return BindingBuilder.bind(testDirectQueue()).to(testDirectExchange()).with(DIRECT_ROUTING);
    }
}
