corvus-ch / rabbitmq-cli-consumer

Consume RabbitMQ messages into any cli program
MIT License
236 stars 36 forks source link

how to add argument "x-dead-letter-exchange=xxxx" in command line? #79

Open gonzalo opened 4 years ago

gonzalo commented 4 years ago

Sorry but I'm unable to find out how to add this argument when starting rabbitmq-cli-consumer from supervisor

This is my command rabbitmq-cli-consumer --strict-exit-code --include --verbose --queue-name answer_save.incoming.queue --configuration /var/www/api/config/rabbitmq/consumer.conf --executable 'php /var/www/api/bin/console queue:consumer --callback answer_save'

And I'm getting this error:

2019/10/16 10:56:23 Queue already declared with conflicting settings. You might want to use --no-declare.
2019/10/16 10:56:23 failed to declare queue: Exception (406) Reason: "PRECONDITION_FAILED - inequivalent arg 'x-dead-letter-exchange' for queue 'answer_save.incoming.queue' in vhost '/': received none but current is the value 'api-events' of type 'longstr'"

Because this queue exists with some other parameters: x-dead-letter-exchange and others...

I need to declare automatically with all arguments but I don't know how to do it. rabbitmq-cli-consumer -help doesn't explain exactly how to do it.

I tried some combinations like rabbitmq-cli-consumer --strict-exit-code --include --verbose --queue-name answer_save.incoming.queue --configuration /var/www/api/config/rabbitmq/consumer.conf --executable 'php /var/www/api/bin/console queue:consumer --callback answer_save' x-dead-letter-exchange=xxxx or rabbitmq-cli-consumer --strict-exit-code --include --verbose --queue-name answer_save.incoming.queue --configuration /var/www/api/config/rabbitmq/consumer.conf --executable 'php /var/www/api/bin/console queue:consumer --callback answer_save' x-dead-letter-exchange:xxxx

...with no success. Obviously I'm doing it on a wrong way. Which is the proper way to add these arguments on command line?

johnduro commented 4 years ago

Hey @gonzalo ,

You cannot set all parameters from command line, for some of them, dead letter exchange for example, you'll have to use a configuration file.

On the command line it'll look like this :

./rabbit-cli-consumer -c path/to/conf/file.conf

Find an example here for the configuration file.

cansozeri commented 4 years ago

@gonzalo @johnduro Your settings must be the same on RabbitMQ server and on your consumer config if you want to use declare option .

Here is the error is about " in your queue answer_save.incoming.queue - x-dead-letter-exchange is none but you are trying to declare api-events "

I think you have already a queue which is name is "answer_save.incoming.queue", so you can not declare a queue with different options.

So you need to add this to config file.

gonzalo commented 4 years ago

You cannot set all parameters from command line, for some of them, dead letter exchange for example, you'll have to use a configuration file.

That's what I'm afraid of, thank you for your answer

I was trying to set that parameters from command line because I have multiple workers sharing the same consumer.conf (where I set user/pass/host...). This forces me to have separate config file for this specific consumer. A bit annoying, because of the way we deploy our stacks, but possible at the end.

Command line doesn't accept multiple conf files.

Anyway now it solved just created an specific conf for this worker with this code...

[rabbitmq]
host = rabbitmq
port = 5672
username = xxxx
password = xxxx
vhost = /
compression = Off

[logs]
info = /var/log/rabbitmq-consumer-info.log
error = /var/log/rabbitmq-consumer-error.log

[queuesettings]
deadLetterExchange = api-events
deadLetterroutingKey = answer_save.dead-letter.queue
gonzalo commented 4 years ago

...one more thing...

just for illustrative purposes if someone needs it

I also need to declare an exchange and a binding for this queue so finally my conf file is

 [rabbitmq]
host = rabbitmq
port = 5672
username = xxxx
password = xxxx
vhost = /
compression = Off

[logs]
info = /var/log/rabbitmq-consumer-info.log
error = /var/log/rabbitmq-consumer-error.log

[exchange]
name = api-events
type = direct
durable = On

[queuesettings]
deadLetterExchange = api-events
deadLetterroutingKey = answer_save.dead-letter.queue
routingKey = xxxx.answer_save

Many thanks @johnduro and @cansozeri for your help

arturslogins commented 4 years ago

@gonzalo Hey, did you solve your issue with dead letter queue Can you give example for it, how you configure it? Is it possible from consumer forward rejected message to dead letter queue ?