Class AbstractDispatcherMultipleConsumers

All Implemented Interfaces:
Dispatcher
Direct Known Subclasses:
NonPersistentDispatcherMultipleConsumers, PersistentDispatcherMultipleConsumers

public abstract class AbstractDispatcherMultipleConsumers extends AbstractBaseDispatcher
  • Field Details

  • Constructor Details

    • AbstractDispatcherMultipleConsumers

      protected AbstractDispatcherMultipleConsumers(Subscription subscription, org.apache.pulsar.broker.ServiceConfiguration serviceConfig)
  • Method Details

    • isConsumerConnected

      public boolean isConsumerConnected()
    • getConsumers

      public CopyOnWriteArrayList<Consumer> getConsumers()
    • canUnsubscribe

      public boolean canUnsubscribe(Consumer consumer)
    • isClosed

      public boolean isClosed()
    • getType

      public org.apache.pulsar.common.api.proto.CommandSubscribe.SubType getType()
    • isConsumerAvailable

      public abstract boolean isConsumerAvailable(Consumer consumer)
    • cancelPendingRead

      protected void cancelPendingRead()
    • getNextConsumer

      public Consumer 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

      public Consumer getRandomConsumer()
      Get random consumer from consumerList.
      Returns:
      null if no consumer available, else return random consumer from consumerList