I have a small doubt regarding routing key and binding key in RabbitMQ. What I have understood is that producer sends message to an exchange with a "routing key". The queue is bound to the exchange with a binding key. In case of default exchange, I came across a definition like - "Every queue is automatically bound to the Default Exchange with a routing key which is the same as the queue name. "
So here should it be "binding key" instead of routing key?? Or are the terms almost the same?
Every queue is bound to default exchange with a binding key equal to queue name means, internally this is the case-
channel.queueBind(queueName, "", queueName);
Is this correct?? Every queue is bound to default exchange with binding key same as the queue name. Since the default exchange is nothing but a direct exchange with no name, it will match the routing key with the binding key of the queue and route it if they are equal..Am I correct in my understanding? The two terms "binding key" and "routing key" are used little confusingly.
The binding-key is used with the queue. It is the key with which the queue is registered in the exchange.
The routing-key is used with the message. It is the key which will decide which queue(s) does this message should be routed to. Messages can have other type of identifiers for routing, like matchers in Topic Exchange.
Every queue is automatically bound to the default exchange with a routing key which is the same as the queue name.
Now, the routing-key and binding-key is not the same concept. But, here, in the case of Default Exchange, the binding key will be the same as the name of the queue. So, the messages will also have the same routing-key as the Queue name.
So,
channel.queueBind(queueName, "", queueName);
is not exactly the correct thing to do. However, it depends on the type of the exchange, how the queue will be bound to the exchange. In the case of default exchange, it is bind with the name of the queue, so it will be done by the RabbitMQ.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With