spring-amqp implementation of RabbitMq - does it internally use queueDeclarePassive?

Viewed 117

We are migrating from existing classic queues to quorum queues and one of the requirements is that we must declare queue usage as "passive" (i.e. queueDeclarePassive). The intent is to ensure we do not create any queues dynamically and only check for its existence (and fail if it doesn't exist) and then connect.

We have a legacy service that uses spring-amqp and we set the SimpleMessageListenerContainer like so:

SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    container.setConnectionFactory(connectionFactory);
    container.setQueueNames(queue().getName());

...

public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
    RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
    rabbitTemplate.getConnectionFactory().createConnection().createChannel(false);
    return rabbitTemplate;
}

I don't see a way to declare the queue as "passive". In reading the spring.io documentation, I see a description for declarationRetries:

"The number of retry attempts when passive queue declaration fails. Passive queue declaration occurs when the consumer starts or, when consuming from multiple queues, when not all queues were available during initialization."

Does this imply that spring-amqp uses queueDeclarePassive behind the scenes? Is this explicitly documented anywhere? If I'm incorrect, how do I properly ensure queueDeclarePassive is used within this amqp usage?

Thanks in advance!

1 Answers

Does this imply that spring-amqp uses queueDeclarePassive behind the scenes?

It doesn't imply it, it explicitly states it.

queueDeclarePassive is used by the listener containers during startup to verify the configured queue(s) are present.

By default, the SimpleMessageListenerContainer will try 3 times at 5 second intervals, and if the passive declarations fail, the container will stop. The number of attempts and interval can be configured.

The DirectMessageListenerContainer will try indefinitely to passively declare the queue(s) if they don't exist, using its monitorInterval property.

Spring AMQP will only perform non-passive queue declaration (queue creation) if the application context contains Queue @Beans and there is a RabbitAdmin @Bean present.

Related