Announcement Announcement Module
Collapse
No announcement yet.
RabbitAdmin.declare Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • RabbitAdmin.declare

    I have a RabbitAdmin bean declared as follows:

    Code:
         
    @Bean
    public RabbitAdmin rabbitAdmin() {
            RabbitAdmin rAdmin = new RabbitAdmin(connectionFactory);
            rAdmin.declareBinding(binding());
            return rAdmin;
        }
    Everything works, but I have some lingering questions. I changed the name of the Queue used to declare the binding in another bean. I had previously declared it to the RabbitAdmin, but have since removed that line.

    Code:
         
    @Bean
    public RabbitAdmin rabbitAdmin() {
            RabbitAdmin rAdmin = new RabbitAdmin(connectionFactory);
            rAdmin.declareQueue( queue() );
            rAdmin.declareBinding( binding() );
            return rAdmin;
        }

    I noticed that after declaring everthing to the rabbitAdmin, I can go ahead and remove the declaration lines, and the code still works as expect.

    Code:
         
    @Bean
    public RabbitAdmin rabbitAdmin() {
            RabbitAdmin rAdmin = new RabbitAdmin(connectionFactory);
            return rAdmin;
        }
    However, if I decide to change the name of the Queue, I must redeclare everything in the RabbitAdmin before the code runs.

    Does declaring a binding or queue to a rabbitAdmin keep track of everthing declared to it forever? Is it because it's created using a CachingConnectionFactory?

  • #2
    It depends on the characteristics of the queue.

    In general, you don't need to declare these elements yourself. The admin registers itself as a connection listener; when the connection is first opened, the admin looks for all the queues, exchanges, bindings declared in the application context and automatically declares them.

    If a queue is persistent, you don't need to declare it every time but it doesn't hurt if you do (as long as the arguments are not changed).

    Comment

    Working...
    X