Reputation: 12015
Does RabbitMQ create queue/exchange if already exist?
Should I check before create queue and exchange if they are already exist?
Upvotes: 3
Views: 4981
Reputation:
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.
Upvotes: 1