Package org.apache.pulsar.broker.service
Class ConsistentHashingStickyKeyConsumerSelector
- java.lang.Object
-
- org.apache.pulsar.broker.service.ConsistentHashingStickyKeyConsumerSelector
-
- All Implemented Interfaces:
StickyKeyConsumerSelector
public class ConsistentHashingStickyKeyConsumerSelector extends java.lang.Object implements StickyKeyConsumerSelector
This is a consumer selector based fixed hash range. The implementation uses consistent hashing to evenly split, the number of keys assigned to each consumer.
-
-
Field Summary
-
Fields inherited from interface org.apache.pulsar.broker.service.StickyKeyConsumerSelector
DEFAULT_RANGE_SIZE
-
-
Constructor Summary
Constructors Constructor Description ConsistentHashingStickyKeyConsumerSelector(int numberOfPoints)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddConsumer(Consumer consumer)Add a new consumer.java.util.Map<Consumer,java.util.List<org.apache.pulsar.client.api.Range>>getConsumerKeyHashRanges()Get key hash ranges handled by each consumer.voidremoveConsumer(Consumer consumer)Remove the consumer.Consumerselect(int hash)Select a consumer by hash.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.pulsar.broker.service.StickyKeyConsumerSelector
select
-
-
-
-
Method Detail
-
addConsumer
public void addConsumer(Consumer consumer) throws BrokerServiceException.ConsumerAssignException
Description copied from interface:StickyKeyConsumerSelectorAdd a new consumer.- Specified by:
addConsumerin interfaceStickyKeyConsumerSelector- Parameters:
consumer- new consumer- Throws:
BrokerServiceException.ConsumerAssignException
-
removeConsumer
public void removeConsumer(Consumer consumer)
Description copied from interface:StickyKeyConsumerSelectorRemove the consumer.- Specified by:
removeConsumerin interfaceStickyKeyConsumerSelector- Parameters:
consumer- consumer to be removed
-
select
public Consumer select(int hash)
Description copied from interface:StickyKeyConsumerSelectorSelect a consumer by hash.- Specified by:
selectin interfaceStickyKeyConsumerSelector- Parameters:
hash- hash corresponding to sticky key- Returns:
- consumer
-
getConsumerKeyHashRanges
public java.util.Map<Consumer,java.util.List<org.apache.pulsar.client.api.Range>> getConsumerKeyHashRanges()
Description copied from interface:StickyKeyConsumerSelectorGet key hash ranges handled by each consumer.- Specified by:
getConsumerKeyHashRangesin interfaceStickyKeyConsumerSelector- Returns:
- A map where key is a consumer name and value is list of hash range it receiving message for.
-
-