package com.jy.business.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.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@EnableRabbit
@Configuration
public class RabbitConfig {

    /**
     * 添加资金流水队列
     */
    public static final String TRANSACTIONS_QUEUE = "transactionsQueue";

    /**
     * jy项目交换机
     */
    public static final String JY_DIRECT_EXCHANGE = "jyDirectExchange";

    /**
     * 创建一个队列
     */
    @Bean
    public Queue transactionsQueue() {
        return new Queue(TRANSACTIONS_QUEUE, true);
    }

    /**
     * 创建一个Direct类型的交换机
     */
    @Bean
    public DirectExchange jyDirectExchange() {
        return new DirectExchange(JY_DIRECT_EXCHANGE, true, false);
    }

    /**
     * 绑定交换机和队列
     */
    @Bean
    public Binding binding() {
        return BindingBuilder.bind(transactionsQueue()).to(jyDirectExchange()).withQueueName();
    }

}
