summaryrefslogtreecommitdiff
path: root/kafka/partitioner/hashed.py
diff options
context:
space:
mode:
authorbarrotsteindev <barrotstein@gmail.com>2016-09-28 20:30:32 +0300
committerDana Powers <dana.powers@gmail.com>2016-09-28 10:30:32 -0700
commitb8717b4b79462e83344f49bbd42312cf521d84aa (patch)
treec20e9a2f2e33e744702d277cb84e7a08c85d2218 /kafka/partitioner/hashed.py
parent5c784890b6f323ea37c6171a59184e9304cbcb5c (diff)
downloadkafka-python-b8717b4b79462e83344f49bbd42312cf521d84aa.tar.gz
Update Partitioners for use with KafkaProducer (#827)
Diffstat (limited to 'kafka/partitioner/hashed.py')
-rw-r--r--kafka/partitioner/hashed.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/kafka/partitioner/hashed.py b/kafka/partitioner/hashed.py
index 988319b..b6b8f7f 100644
--- a/kafka/partitioner/hashed.py
+++ b/kafka/partitioner/hashed.py
@@ -11,6 +11,11 @@ class Murmur2Partitioner(Partitioner):
the hash of the key. Attempts to apply the same hashing
function as mainline java client.
"""
+ def __call__(self, key, partitions=None, available=None):
+ if available:
+ return self.partition(key, available)
+ return self.partition(key, partitions)
+
def partition(self, key, partitions=None):
if not partitions:
partitions = self.partitions
@@ -21,12 +26,15 @@ class Murmur2Partitioner(Partitioner):
return partitions[idx]
-class LegacyPartitioner(Partitioner):
+class LegacyPartitioner(object):
"""DEPRECATED -- See Issue 374
Implements a partitioner which selects the target partition based on
the hash of the key
"""
+ def __init__(self, partitions):
+ self.partitions = partitions
+
def partition(self, key, partitions=None):
if not partitions:
partitions = self.partitions