package ru.ibs.socrates.confexporter.external.sdtllmraggateconf.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
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;


@Configuration
public class RabbitConfig {

  /**
   * Fanout Exchange
   * 
   * @param exchangeName
   * @return
   */
  @Bean
  public FanoutExchange fanoutExchange(
      @Value("${spring.rabbitmq.template.exchange}") String exchangeName) {
    return new FanoutExchange(exchangeName);
  }

  /**
   * Очередь
   * 
   * @param queueName
   * @return
   */
  @Bean
  public Queue myQueue(
      @Value("${spring.rabbitmq.queue.name}") String queueName) {
    // [durable=false, exclusive=false, autoDelete=false]
    return new Queue(queueName, true, false, false);
  }

  /**
   * Биндинг очереди к Fanout Exchange
   * 
   * @param myQueue
   * @param fanoutExchange
   * @return
   */
  @Bean
  public Binding binding(Queue myQueue, FanoutExchange fanoutExchange) {
    return BindingBuilder.bind(myQueue).to(fanoutExchange);
  }

}
