Configuring RabbitAdmin

RabbitAdmin is used to declare the exchanges, queues, and binding that needs to be ready on startup. RabbitAdmin does the automatic declaration of the queues, exchanges, and binding. The main benefit of this auto-declaration is that if the connection is disconnected for some reason, they will be applied automatically when the connection is re-established. The following code configures RabbitAdmin:

@Bean
public RabbitAdmin rabbitAdmin() {
RabbitAdmin admin = new RabbitAdmin(connectionFactory());
admin.declareQueue(queue());
admin.declareExchange(exchange());
admin.declareBinding(exchangeBinding(exchange(), queue()));
return admin;
}

rabbitAdmin() will declare the Queue, Exchange, and Binding. The RabbitAdmin constructor creates an instance using the connectionFactory() bean and it must not be null.

RabbitAdmin performs automatic declaration only when the CachingConnectionFactory cache mode is CHANNEL (it is by default). The reason for this limitation is because it may be the case that exclusive and autodelete queues may be bound to the connection.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset