[rabbitmq-discuss] request, reply connections and channels

Emile Joubert emile at rabbitmq.com
Mon Aug 6 11:39:44 BST 2012


On 06/08/12 04:44, cogitate wrote:
> i'd like to throw an exception/error when basicPublish is called on a
> non-existent exchange [on the broker].
> it seems setting mandatory=true, and registering a returnListener on the
> channel won't work (since, the connection for req and reply are different )

The mandatory option is relevant when a message cannot be routed to a
queue. Attempting to publish to a non-existent exchange is a very
different issue and the return-listener is not used to report this

> what are my options besides switching to using the same connection for
> req/reply? any configuration on the broker that might help will be quite
> useful.

A possible option is to guarantee that the exchange cannot be absent.
Assign permissions in a way that guarantees exchanges cannot be deleted.

Another option is to use publisher confirms:
These should inform the client of a channel exception, though I don't
know exactly how this gets reported in Pika.

> # using python client:
> not sure why, but it simply works! i don't even set mandatory=true. the pika
> client simply doesn't allow me to publish to a non-existent exchange on the
> broker.

I'm not familiar enough with Pika to explain this, but regardless of the
AMQP client you choose to use, is is impossible to use the same channel
to do useful work after a channel exception was raised. The mandatory
flag is unlikely to play any part.

>  it seems i can solve the problem by
> reqChannel.exchangeDeclarePassive(<non_existent_exchange>)
> is this advisable for every call from a performance point-of-view?

When you publish to a non-existent exchange a channel exception is
raised, closing the channel. Publishing is an asynchronous operation, so
the caller is unaware of this until the next synchronous operation.
Issuing an exchange passive declare is a synchronous operation which
will alert the caller if the channel has closed. You could use any other
synchronous operation.

Interspersing publishes with synchronous operations is likely to reduce
the maximum possible publish speed dramatically.


More information about the rabbitmq-discuss mailing list