4

I am using Spring Boot with spring-rabbitmq. My connection factory is configured in application.properties and it seems to be nice.

My aim is: during start check if exists queue if specific name, and in case of absence create such queue. I am not sure how to deal with it. What beans should I create in config class? From what I read it should be RabbitAdmin, however I am not sure about it. Can you help me?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • Possible duplicate of [How to get Spring RabbitMQ to create a new Queue?](https://stackoverflow.com/questions/16370911/how-to-get-spring-rabbitmq-to-create-a-new-queue) – Rafael Renan Pacheco Jul 03 '19 at 17:27

1 Answers1

6

Everything is described clearly in the Reference Manual:

The AMQP specification describes how the protocol can be used to configure Queues, Exchanges and Bindings on the broker. These operations which are portable from the 0.8 specification and higher are present in the AmqpAdmin interface in the org.springframework.amqp.core package.

And further:

When the CachingConnectionFactory cache mode is CHANNEL (the default), the RabbitAdmin implementation does automatic lazy declaration of Queues, Exchanges and Bindings declared in the same ApplicationContext.

So, you should declare Queue, Exchange and Binding beans in your application context and AmqpAdmin will take care about their definition on the target Broker.

There must be a note that according AMQP protocol, if entity already exists on the Broker, the declaration is just silent and idempotent.

So, in your case you don't need to worry about queues existence and just provide their declarations as beans in the application context.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Thats' incredible, spring-amqp is brilliant, every default settings is reasonable and there is easy way to config it. –  Mar 25 '17 at 23:04
  • 1
    Hi Artem, unfortunatly the link at https://docs.spring.io/spring-amqp/reference/html/_reference.html#broker-configuration is dead. – Barny Mar 22 '19 at 12:13
  • We have an application A that declares it's own queue but another application B listens to that queue from app A because we have Spring's `Queue` on B side it tries to declare it but the definition is different so it fails saying it can't modify the existing queue. How can I disable auto declaration on B? – xbmono Sep 14 '20 at 06:45
  • Probably your question deserves its own SO thread with more details. – Artem Bilan Sep 14 '20 at 18:12