Precondition failure: Consumer expects “fanout” but producer actual is “topic”

5,183 views
Skip to first unread message

RanjitH R

unread,
Feb 5, 2019, 7:00:10 AM2/5/19
to rabbitmq-users

 have a docker environment where messaging service(rabbitmq) and my services(myapp) are configured in docker. I try to consume the messages published by myapp. myapp produces the messages of type "fanout" in a given message channel and in consumer code, I try setup the rabbitmq intricacies so that messages of type "fanout" can be consumed.

consumer sample:
factry = newConnectionFactory();
factry.setHost(MYHOST);
connection.newConnection();
chnl = connection.createChannel();
channel.exchangeDeclare("MYEXCHG","fanout",true);
.....
and so on.

When consumer sets the rabbitmq thingy as shown above: I get following PRECONDITION error: Caused by:

com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method(reply-code=406, reply-text=PRECONDITION_FAILED - inequivalent arg 'type' for exchange 'applicationStatus' in vhost '/': received 'fanout' but current is 'topic', class-id=40, method-id=10)

It means that the consumer code has recived message of exchange type 'fanout' but currently it has been configured to receive messages of exchange type 'topic'.



I have enough analysed the producer code and consumer code. Still I could not narrow down the issue. My ask here is: Can i configure the channel in such a way that I will be able to accept any type of messages sent by producer.

Say Producer P1 produces msgs from exchange type 'direct' and P2 produces msgs from exchange type 'fanout'. Can I have a common consumer code so that I will be able to receive msgs irrespective of its exchange type(i.e.,produced from P1 and P2...)


Really appreciate the help in this forum.

Michael Klishin

unread,
Feb 5, 2019, 7:35:40 AM2/5/19
to rabbitmq-users
Exchanges and queues are immutable. You cannot redeclare an exchange with a different type,
as the message suggests.

The error means a client tried to declare an existing exchange with a different type, not that it "received it" with a different type.

See [1].

RanjitH R

unread,
Feb 6, 2019, 6:06:19 AM2/6/19
to rabbitmq-users

Thank you for the clarification. 

I am trying to write up a test scenario(docker environ) to validate the producer code.The producer code has a 'fanout' exchange type.The rabbitmq and producer code all runs on docker. So when I try to setup the consumer code(fanout) as depicted in the code snippet, I get PRECONDITION_FAILURE. 

In nutshell, Should i be avoiding redeclaring the exchange type in consumer code? and depend on the queue? 

Arnaud Cogoluègnes

unread,
Feb 6, 2019, 9:52:05 AM2/6/19
to rabbitm...@googlegroups.com
Ideally the consumer program should depend only on the queue, but this
depends on the structure of your system. To answer a question in your
first email, a same consumer can receive messages from any exchanges,
what matters is the queue the consumer listens on and how the messages
are routed to this queue from whatever exchange. A good read about the
AMQP model should make this clearer [1].

[1] https://www.rabbitmq.com/tutorials/amqp-concepts.html
> --
> You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
> To post to this group, send email to rabbitm...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages