Class AbstractDispatcherMultipleConsumers
- All Implemented Interfaces:
Dispatcher
- Direct Known Subclasses:
NonPersistentDispatcherMultipleConsumers,PersistentDispatcherMultipleConsumers
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final CopyOnWriteArrayList<Consumer>protected final com.carrotsearch.hppc.ObjectSet<Consumer>protected intprotected static final intprotected static final AtomicIntegerFieldUpdater<AbstractDispatcherMultipleConsumers>protected static final intFields inherited from class org.apache.pulsar.broker.service.AbstractBaseDispatcher
dispatchThrottlingOnBatchMessageEnabled, serviceConfigFields inherited from class org.apache.pulsar.broker.service.EntryFilterSupport
entryFilters, filterContext, subscription -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractDispatcherMultipleConsumers(Subscription subscription, org.apache.pulsar.broker.ServiceConfiguration serviceConfig) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbooleancanUnsubscribe(Consumer consumer) Broker gives more priority while dispatching messages.Get random consumer from consumerList.org.apache.pulsar.common.api.proto.CommandSubscribe.SubTypegetType()booleanisClosed()abstract booleanisConsumerAvailable(Consumer consumer) booleanMethods inherited from class org.apache.pulsar.broker.service.AbstractBaseDispatcher
computeReadLimits, filterEntriesForConsumer, filterEntriesForConsumer, getFilterAcceptedMsgCount, getFilterProcessedMsgCount, getFilterRejectedMsgCount, getFilterRescheduledMsgCount, getSubscriptionName, isConsumersExceededOnSubscription, isConsumersExceededOnSubscription, peekStickyKey, reachDispatchRateLimit, reScheduleRead, resetCloseFuture, updateMessagesToRead, updatePendingBytesToDispatchMethods inherited from class org.apache.pulsar.broker.service.EntryFilterSupport
runFiltersForEntryMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.pulsar.broker.service.Dispatcher
addConsumer, addUnAckedMessages, checkAndUnblockIfStuck, clearDelayedMessages, close, consumerFlow, cursorIsReset, disconnectActiveConsumers, disconnectAllConsumers, disconnectAllConsumers, getNumberOfDelayedMessages, getRateLimiter, getRedeliveryTracker, initializeDispatchRateLimiterIfNeeded, markDeletePositionMoveForward, redeliverUnacknowledgedMessages, redeliverUnacknowledgedMessages, removeConsumer, reset, trackDelayedDelivery, updateRateLimiter
-
Field Details
-
consumerList
-
consumerSet
-
currentConsumerRoundRobinIndex
protected volatile int currentConsumerRoundRobinIndex -
FALSE
protected static final int FALSE- See Also:
-
TRUE
protected static final int TRUE- See Also:
-
IS_CLOSED_UPDATER
protected static final AtomicIntegerFieldUpdater<AbstractDispatcherMultipleConsumers> IS_CLOSED_UPDATER
-
-
Constructor Details
-
AbstractDispatcherMultipleConsumers
protected AbstractDispatcherMultipleConsumers(Subscription subscription, org.apache.pulsar.broker.ServiceConfiguration serviceConfig)
-
-
Method Details
-
isConsumerConnected
public boolean isConsumerConnected() -
getConsumers
-
canUnsubscribe
-
isClosed
public boolean isClosed() -
getType
public org.apache.pulsar.common.api.proto.CommandSubscribe.SubType getType() -
isConsumerAvailable
-
cancelPendingRead
protected void cancelPendingRead() -
getNextConsumer
Broker gives more priority while dispatching messages. Here, broker follows descending priorities. (eg: 0=max-priority, 1, 2,..)
Broker will first dispatch messages to max priority-level consumers if they have permits, else broker will consider next priority level consumers. Also on the same priority-level, it selects consumer in round-robin manner.
If subscription has consumer-A with priorityLevel 1 and Consumer-B with priorityLevel 2 then broker will dispatch messages to only consumer-A until it runs out permit and then broker starts dispatching messages to Consumer-B.
Consumer PriorityLevel Permits C1 0 2 C2 0 1 C3 0 1 C4 1 2 C5 1 1 Result of getNextConsumer(): C1, C2, C3, C1, C4, C5, C4
Algorithm: 1. consumerList: it stores consumers in sorted-list: max-priority stored first 2. currentConsumerRoundRobinIndex: it always stores last served consumer-index Each time getNextConsumer() is called:
1. It always starts to traverse from the max-priority consumer (first element) from sorted-list 2. Consumers on same priority-level will be treated equally and it tries to pick one of them in round-robin manner 3. If consumer is not available on given priority-level then only it will go to the next lower priority-level consumers 4. Returns null in case it doesn't find any available consumer
- Returns:
- nextAvailableConsumer
-
getRandomConsumer
Get random consumer from consumerList.- Returns:
- null if no consumer available, else return random consumer from consumerList
-