package com.itheima.message.mq.conf;

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

/*****
 * @Author: http://www.itheima.com
 * @Description: com.itheima.config.RabbitMQConfig
 ****/
@Configuration
public class RabbitMQConfig {

    /***
     * 声明交换机
     */
    @Bean(name = "redExchange")
    public Exchange topicExchange(){
        return ExchangeBuilder.directExchange("exchange.direct").durable(true).build();
    }

    /***
     * 声明队列
     */
    @Bean(name = "redMessageQueue")
    public Queue itemQueue(){
        return QueueBuilder.durable("redmessage.queue").build();
    }

    /***
     * 队列绑定到交换机上
     */
    @Bean
    public Binding itemQueueExchange(@Qualifier("redMessageQueue")Queue queue,
                                     @Qualifier("redExchange")Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("redmessage.queue").noargs();
    }
}