[rabbitmq-discuss] Passive versus active declaration of exchanges and queues

Matthias Radestock matthias at rabbitmq.com
Wed Jul 7 11:54:50 BST 2010


Irmo,

On 29/06/10 08:44, Irmo Manie wrote:
> Since 1.8.0 the passive declaration is separated, taking only a name as
> parameter and will not declare anything if the exchange or queue is not
> there yet.
> This does makes sense, so in theory, when wanting a passive declaration
> over active, you would first try passive and then active.

That is usually an anti-pattern since it's racy. Another client might 
create/remove the exchange after the passive declaration. Just actively 
declare the exchange instead.

> Now the problem:
>
> If passive declaration fails, it not only throws an exception, it also
> closes the channel.

AMQP only has two kinds of errors - those that close that channel and 
those that close the connection. Channel creation/closure is quite cheap 
in rabbit, so the former type of errors are quite lightweight.

Now, perhaps passive declaration should return a not-found response 
rather than a not-found error, but the protocol is what it is.

> Questions:
>
> - What is the added value of the Exchange.DeclareOk result?

So you know that the operation has completed successfully.

> - Why is there no API call available to check if an exchange exists (and
> with which parameters) so that this exception can be prevented?

As noted above, just perform an active declaration instead.

I have yet to find a genuine use case for passive declarations. But the 
operations are defined in the protocol and quite easy to implement, so 
rabbit supports them.


Regards,

Matthias.


More information about the rabbitmq-discuss mailing list