content: package dev.agitrubard.report.config;
  
  import org.springframework.amqp.core.Binding;
  import org.springframework.amqp.core.BindingBuilder;
  import org.springframework.amqp.core.Queue;
  import org.springframework.amqp.core.TopicExchange;
  import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
  import org.springframework.amqp.rabbit.connection.ConnectionFactory;
  import org.springframework.amqp.rabbit.core.RabbitTemplate;
  import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
  import org.springframework.amqp.support.converter.MessageConverter;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  
  @Configuration
  public class RabbitMQReportConfiguration {
  
      public static final String EXCHANGE_NAME = "report.exchange";
      public static final String QUEUE_NAME = "report.queue";
      public static final String ROUTING_KEY = "report.key";
  
      @Bean
      TopicExchange reportExchange() {
          return new TopicExchange(EXCHANGE_NAME);
      }
  
      @Bean
      Queue reportQueue() {
          return new Queue(QUEUE_NAME, true);
      }
  
      @Bean
      Binding binding(Queue reportQueue, TopicExchange reportExchange) {
          return BindingBuilder
                  .bind(reportQueue)
                  .to(reportExchange)
                  .with(ROUTING_KEY);
      }
  
      @Bean
      MessageConverter jsonMessageConverter() {
          return new Jackson2JsonMessageConverter();
      }
  
      @Bean
      RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory,
                                    MessageConverter jsonMessageConverter) {
  
          RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
          rabbitTemplate.setMessageConverter(jsonMessageConverter);
          return rabbitTemplate;
      }
  
      @Bean
      SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(ConnectionFactory connectionFactory,
                                                                          MessageConverter jsonMessageConverter) {
  
          SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
          factory.setConnectionFactory(connectionFactory);
          factory.setMessageConverter(jsonMessageConverter);
          return factory;
      }
  
  }
  