0

I am trying to create a new queue in RabbitMQ using Spring AMQP on server startup of my web application. I am not getting the exact configuration code how to achieve it. Below is my code snippet. Please correct the following.

@Configuration
public class RabbitMQConfiguration {

     @Bean
        public ConnectionFactory rabbitConnectionFactory() {
            CachingConnectionFactory connectionFactory = new CachingConnectionFactory("10.165.18.29");
            connectionFactory.setUsername("User");
            connectionFactory.setPassword("user");
            return connectionFactory;
        }

     @Bean
        public SimpleMessageListenerContainer messageListenerContainer() {
            SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
            container.setConnectionFactory(rabbitConnectionFactory());
            container.addQueueNames("create.queue");
            container.setMessageListener(exampleListener());
            return container;
        }

     @Bean
        public MessageListener exampleListener() {
            return new MessageListener() {
                public void onMessage(Message message) {
                    System.out.println("received: " + message);
                }
            };
        }
}
Nayantara Jeyaraj
  • 2,624
  • 7
  • 34
  • 63
Chandan
  • 333
  • 1
  • 6
  • 14

1 Answers1

0

See the documentation.

Simply add <rabbit:queue ... /> beans and a <rabbit:admin ... /> and the admin will automatically declare the queues when the connection is first established.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179