Bootstrap FreeKB - RabbitMQ - Create Exchange using the rabbitmqadmin command
RabbitMQ - Create Exchange using the rabbitmqadmin command

Updated:   |  RabbitMQ articles

This assumes you have downloaded and setup the rabbitmqadmin command line tool.

declare exchange can be used to create an exchange. In this example, an exchange named exchange001 is as a direct exchange.

rabbitmqadmin declare exchange --vhost=/ name=exchange001 type=direct

 

If the exchange is created, the following should be returned.

exchange declared

 

With a direct exchange, when the producer publishes a messages to the exchange with a routing key, the exchange must be bound to a queue with the exact same routing key. For example, if the producer publishes a message to exchange001 with routing key key001, then exchange001 would need to be bound to a queue with routing key key001.

With a topic exchange, when the producer publishes a messages to the exchange with a routing key, the exchange can be bound to one or more queues with a regular expression matching the routing key. For example, if the producer publishes a message to exchange001 with routing key key001, then exchange001 could be found to queues with a regular expression such as key.*.

With a headers exchange, the exchange will match one or all of the headers in the message to know which target queues the message should be routed to. For example, if the header exchange has arguments x-match: any and foo: bar, if the producer publishes a message to exchange001 with header foo: bar, then the message will be routed to the queues that are bound to the exchange. A routing key would not be used in the binding between the header exchange and queues.




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 8ef7b1 in the box below so that we can be sure you are a human.