When using consistent hashing exchange in rabbitmq, I came across two conflicting sentences on how the position of a queue is determined on the hash ring.
When binding a queue to the consistent hashing exchange, the routing_key
serves as a parameter to influence how the queue gets mapped to the ring. Consider the following code snippet in python.
channel.exchange_declare(exchange='samplehashing', exchange_type='x-consistent-hash')
channel.queue_declare(queue='letterbox1')
channel.queue_bind('letterbox1', 'samplehashing', routing_key='1')
def callback_1(ch, method, properties, body):
print(f'queue 1 received new message: {body}')
channel.basic_consume(queue='letterbox1', auto_ack=True, on_message_callback=callback_1)
I also read somewhere that:
In a consistent hashing exchange, each queue is assigned positions on the hash ring. This is typically done by hashing the queue's name or ID to determine where it sits on the ring.
Which approach is correct?