package com.zcxk.config;

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

@Configuration
public class RabbitConfig {
    @Value("${receive.queue.name}")
    private  String receiveQueueName;
    @Value("${receive.exchange.name}")
    private  String receiveExchangeName;
    @Value("${receive.routing.key}")
    private  String receiveRoutingKey;
    @Value("${dispath.routing.key}")
    private  String dispathRoutingKey;
    @Value("${dispath.queue}")
    private  String dispathQueue;


    @Bean
    public Queue dispathQueue() {
        return QueueBuilder.nonDurable(dispathQueue).build();
    }
    @Bean
    public Queue receiveQueue() {

        return new Queue(receiveQueueName, false, false, false, null);
    }

    @Bean
    public Exchange exchange() {

        return new TopicExchange(receiveExchangeName, false, false, null);
    }


    @Bean
    public Binding receiveBinding() {
        return new Binding(receiveQueueName,
                Binding.DestinationType.QUEUE,
                receiveExchangeName,
                receiveRoutingKey,
                null);
    }
    @Bean
    public Binding dispathBinding() {
        return new Binding(dispathQueue,
                Binding.DestinationType.QUEUE,
                receiveExchangeName,
                dispathRoutingKey,
                null);
    }

}
