最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

python 3.x - RabbitMQ consistent hashing exchange - queue position - Stack Overflow

matteradmin7PV0评论

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?

Post a comment

comment list (0)

  1. No comments so far