Skip to content

Instantly share code, notes, and snippets.

@jeremy-smith-maco
Created July 23, 2024 23:01
Show Gist options
  • Save jeremy-smith-maco/1dc7eeee7ae189678e98de93fdbebf8f to your computer and use it in GitHub Desktop.
Save jeremy-smith-maco/1dc7eeee7ae189678e98de93fdbebf8f to your computer and use it in GitHub Desktop.
Reproduction case for no hash header key in headers
#!/usr/bin/env python
import pika
import time
conn = pika.BlockingConnection(pika.ConnectionParameters(host='host.docker.internal'))
ch = conn.channel()
args = {u'hash-header': u'hash-on'}
ch.exchange_declare(exchange='e2',
exchange_type='x-consistent-hash',
arguments=args,
durable=True)
for q in ['q1', 'q2', 'q3', 'q4']:
ch.queue_declare(queue=q, durable=True)
ch.queue_purge(queue=q)
for q in ['q1', 'q2']:
ch.queue_bind(exchange='e2', queue=q, routing_key='1')
for q in ['q3', 'q4']:
ch.queue_bind(exchange='e2', queue=q, routing_key='2')
n = 100000
for rk in list(map(lambda s: str(s), range(0, n))):
#hdrs = {u'hash-on': rk}
# If we don't include the hash-on header it will break the server
hdrs = {}
ch.basic_publish(exchange='e2',
routing_key='',
body='',
properties=pika.BasicProperties(content_type='text/plain',
delivery_mode=2,
headers=hdrs))
print('Done publishing.')
print('Waiting for routing to finish...')
# in order to keep this example simpler and focused,
# wait for a few seconds instead of using publisher confirms and waiting for those
time.sleep(5)
print('Done.')
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment