Skip to content

Instantly share code, notes, and snippets.

@noxdafox
Last active February 24, 2023 14:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noxdafox/ad1fb4c3769e06a888c3a542fc08c544 to your computer and use it in GitHub Desktop.
Save noxdafox/ad1fb4c3769e06a888c3a542fc08c544 to your computer and use it in GitHub Desktop.
Usage example of RabbitMQ exchange deduplication plugin
import pika
from hashlib import md5
RABBITMQ_URL = 'amqp://guest:guest@localhost:5672/'
parameters = pika.URLParameters(RABBITMQ_URL)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
# Declare exchange, queue and bind them together
channel.exchange_declare(
exchange='test_exchange',
exchange_type='x-message-deduplication',
arguments=dict({'x-cache-size': '5'}))
channel.queue_declare(queue='test_queue')
channel.queue_bind('test_queue', 'test_exchange')
# The message will be deduplicated based on its content
# The MD5 digest of the content is used as deduplication header
message_body = 'hello world'
message_deduplication_header = md5(message_body.encode()).hexdigest()
# Only one message shall be routed to the queue
for _ in range(100):
channel.basic_publish(
exchange='test_exchange',
routing_key='',
body=message_body,
properties=pika.BasicProperties(
headers={'x-deduplication-header': message_deduplication_header}))
channel.close()
connection.close()
@ryanermita
Copy link

is there any example using queue level deduplication in kumbo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment