I am trying to setup a variety of exchanges and queues in RabbitMQ via a script calling rabbitmqadmin. While I can declare a queue, I am not able to find any way to send 'x-dead-letter-exchange' or 'x-dead-letter-routing-key' arguments in the declaration. Is this possible?
Yes, this is possible by specifying JSON in 'arguments' argument:
call rabbitmqadmin.py declare queue name=MyQueue arguments={\"x-dead-letter-exchange\":\"MyExchange\",\"x-dead-letter-routing-key\":\"MyRoutingKey\"}
Note: this is except from Windows batch file. (on other OS some syntax might be different)
For those interested, the solution was to do 'rabbitmqadmin export rabbit.config', change the file to include the necessary exchanges, queues and bindings, then 'rabbitmqadmin import rabbit.config'. Not an optimal solution, but functional.
Related
When creating a queue in the RabbitMQ UI with de default options, it shows in the features column D for durable, and Args with x-queue-type: classic.
When creating it by code, you can create like this in python:
channel.queue_declare('QueueName', durable=True), but it is different from the queue created by the UI, without the Args feature of x-queue-type: classic, but it's type is a classic queue as indicated.
In python, you can create a queue that is just like the one created by default in the UI with this:
channel.queue_declare('QueueName', durable=True, arguments={'x-queue-type':'classic'})
My doubt is, since both queue types are classical, whats the difference between the one with the argument x-queue-type: classic and the one without, assuming all rest is the same?
In this image an example as shown in the RabbitMQ UI:
In the new RabbitMQ versions, there are different types of queues.
Classic queues ( the classic queues RabbitMQ has for a while)
Quorum queues ( Type of queues available from rabbitmq 3.8)
Streaming queues ( released >= 3.9)
When you declare a queue using a client, if you don't specify anything the server automatically tag the queues with x-queue-type: classic
My doubt is, since both queue types are classical, whats the difference between the one with the argument x-queue-type: classic and the one without, assuming all rest is the same?
It is the same
Does RabbitMQ create queue/exchange if already exist?
Should I check before create queue and exchange if they are already exist?
The RabbitMQ server does not by itself create exchanges or queues. You must use the web admin GUI, a command line tool, or create exchanges and queues over a connection opened by a client. The last option is a good way to create exchanges, queues and bindings as needed by a client on the fly.
It is important to note that an exchange or queue, once created, can not be created again with different properties. For example, if your client creates a fanout exchange, it can not create the same exchange again as a direct exchange. It is safe to create it again with the same type and properties as where used when it was first created. This just does nothing and will leave it unchanged. But trying to create it with a different type or properties will result in an error.
The same is true for queues. Creating it again with identical properties is fine, using different properties will result in an error.
It is not necessary to check for an exchange or queue to exist if you can make sure that you always create it the same way.
I'm in the process of implementing various remote methods/RPCs on the top of AMQP (RabbitMQ in particular). When a worker (or a client) comes online, it could, in theory, declare (create) a queue on the exchange. The other approach is to just start using a queue and assume that it already exists on the exchange.
Which approach is more common? Creating queues manually has a higher administrative cost, maybe; however, it can result in a more consistent environment if we decouple queue management from queue usage.
It depends what is the requirement. If you have a fixed number of queues and dont need it to be generated dynamically, then go for manual. Example : It is a integration application and I know I have 3 consumers A,B,C then I will manually create 3 queues. Another example in a chat application for every logged in user I want to create a queue, in that case queues should be created programatically. And in case manual creation, you have more control to implement permissions and ACLs.
Meanwhile I found out that according to RabbitMQ applications should take care of managing the queues they use.
In all the examples I find online, I see the exchange and the queue being declared before a messages are consumed.
Declaring the exchange seems weird, because, why would I do it? I'm consuming a queue, which might be bound to multiple exchanges (or to none, maybe it just have old messages waiting in it).
also, I can't think of why I would declare a queue. This will require me to know information about the queue that I don't need to know to consume it (like auto_delete and durability).
When I tested it locally, I can consume a queue without declaring anything. It works. So I'm left wondering, why does every example I've seen online, declare the exchange and queue, even if it just consumes it?
thanks!!!
"All" the example you saw are self contained. And they trying to give you a working example. Because in case you don't have all the components setted up, your example will fail.
In terms of "why I would declare a queue". The real-life example is when your consumer wants to consume messages that are relevant with the current configuration. In this case it will create an exclusive ( no one else can connect to this queue ) and will start consume messages.
Back to your answer. No you don't need to do this. You can pre-create exchange, binding and queue ahead of time and then just pass the names to the code.
In general, you don’t need declare exchange and queue in consumer. You must assemble "exchanges/queues" topology somewhere else. It's like schema in database.
But always there are exceptions.
When you need "private" queue (exclusive=true) for real-time processing, consumer must know (by configuration) about source exchange and bind own queue to it.
In other case i can imagine situations where publisher declare exchange and consumers can discover it using some convention (pattern) for exchange naming.
When you create a queue, you can specify time-to-leave of the messages, deletion of the queue if it has not been used for some time etc.
Those parameters are passed via a dictionary ; is there a place where you can find the proper key-values list accepted ?
“Arguments” are amqp BasicProperties
http://www.rabbitmq.com/releases/rabbitmq-java-client/v3.2.4/rabbitmq-java-client-javadoc-3.2.4/com/rabbitmq/client/AMQP.BasicProperties.html
Some AMQP broker use the BasicProperties to implement their extensions, for example Time-To-Live extension is an RabbitMQ extension.
If you change the broker you lose this functionality.
Read http://www.rabbitmq.com/extensions.html to see the RabbitMQ extensions.
Anyway you can use the properties as you prefer, for example you can add an your custom key value.
The class http://www.rabbitmq.com/releases//rabbitmq-java-client/current-javadoc/com/rabbitmq/client/MessageProperties.html contains some pre-built BasicProperties.