メッセージの重複排除とConsistent Hash Exchangeプラグイン
負荷分散のためのConsistent Hash Exchangeと、Exactly-Once処理を維持する重複排除戦略という、実用的なRabbitMQプラグインを2つ紹介します。
「メッセージの重複排除とConsistent Hash Exchangeプラグイン」はCoddyKit上の無料RabbitMQ Messaging & Async Systemsレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはRabbitMQ Messaging & Async Systems学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 RabbitMQ Messaging & Async Systemsコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Beyond Built-in Exchanges
RabbitMQ plugins extend the broker with new exchange types and behaviors. Two useful ones are the consistent hash exchange and message deduplication plugins.
The Load Distribution Problem
Fanout broadcasts to all queues; direct sends to matched queues. Neither evenly spreads a stream across a set of queues by a key.
The consistent hash exchange solves this.
Enabling the Plugin
Enable the plugin on the broker before use.
rabbitmq-plugins enable rabbitmq_consistent_hash_exchangeDeclaring the Exchange
Declare an exchange of type x-consistent-hash.
channel.exchange_declare(
exchange='shards',
exchange_type='x-consistent-hash'
)Binding With Weights
Bind queues with a numeric weight as the binding key. Higher weight means a larger share of the hash ring.
channel.queue_bind(queue='shard-1', exchange='shards', routing_key='10')
channel.queue_bind(queue='shard-2', exchange='shards', routing_key='10')How Hashing Distributes
The exchange hashes each message's routing key and maps it onto the ring, sending it to one bound queue. The same key always lands on the same queue, giving sticky distribution.
Use Cases for Hashing
- Sharding work by customer or entity id
- Keeping per-key ordering across parallel workers
- Even load spread without manual partitioning
The Duplicate Delivery Problem
RabbitMQ guarantees at-least-once delivery, so retries can cause duplicates. Deduplication ensures the same logical message is processed once.
Deduplication Plugin
The community deduplication plugin adds an exchange that drops messages carrying a recently seen deduplication header within a TTL window.
props = pika.BasicProperties(headers={'x-deduplication-header': 'order-42'})Plugin vs Application Dedup
The plugin is convenient but bounded by its cache window. For strong guarantees, also store processed ids in your application database as a backstop.
Operational Notes
- Plugins must be enabled on every node in a cluster
- Verify version compatibility with your broker
- Test failover behavior before relying on it
Quick Check
Test your plugin knowledge.
Recap
The consistent hash exchange distributes a message stream evenly and stickily across queues by hashing the routing key, while deduplication plugins drop repeated messages within a cache window.
Enable plugins on all cluster nodes and back deduplication with application-level checks for strong guarantees.
よくある質問
「メッセージの重複排除とConsistent Hash Exchangeプラグイン」レッスンは無料ですか?
はい。「メッセージの重複排除とConsistent Hash Exchangeプラグイン」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、RabbitMQ Messaging & Async Systemsコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 RabbitMQ Messaging & Async Systemsコースには全4レッスンが含まれています。
「メッセージの重複排除とConsistent Hash Exchangeプラグイン」で何を学びますか?
負荷分散のためのConsistent Hash Exchangeと、Exactly-Once処理を維持する重複排除戦略という、実用的なRabbitMQプラグインを2つ紹介します。 ブラウザで直接実行するハンズオンコードでRabbitMQ Messaging & Async Systemsを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
RabbitMQ Messaging & Async Systemsを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのRabbitMQ Messaging & Async Systemsは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「メッセージの重複排除とConsistent Hash Exchangeプラグイン」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このRabbitMQ Messaging & Async Systemsレッスンでコードを書いて実行できますか?
はい。すべてのRabbitMQ Messaging & Async Systemsレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- Delayed Messagesプラグイン
- フェデレーション向けShovelプラグイン
- クラスタリング向けFederationプラグイン
- メッセージの重複排除とConsistent Hash Exchangeプラグイン