Class: Kafka::RoundRobinAssignmentStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/kafka/round_robin_assignment_strategy.rb

Overview

A consumer group partition assignment strategy that assigns partitions to consumers in a round-robin fashion.

Instance Method Summary collapse

Instance Method Details

#call(cluster:, members:, partitions:) ⇒ Hash<String, Array<Kafka::ConsumerGroup::Assignor::Partition>] a hash mapping member ids to partitions.

Assign the topic partitions to the group members.

Parameters:

Returns:



21
22
23
24
25
26
27
28
29
# File 'lib/kafka/round_robin_assignment_strategy.rb', line 21

def call(cluster:, members:, partitions:)
  member_ids = members.keys
  partitions_per_member = Hash.new {|h, k| h[k] = [] }
  partitions.each_with_index do |partition, index|
    partitions_per_member[member_ids[index % member_ids.count]] << partition
  end

  partitions_per_member
end

#protocol_nameObject



8
9
10
# File 'lib/kafka/round_robin_assignment_strategy.rb', line 8

def protocol_name
  "roundrobin"
end