class Karafka::Routing::ConsumerGroup

Object used to describe a single consumer group that is going to subscribe to given topics It is a part of Karafka's DSL

Attributes

id[R]
name[R]
topics[R]

Public Class Methods

new(name) click to toggle source

@param name [String, Symbol] raw name of this consumer group. Raw means, that it does not

yet have an application client_id namespace, this will be added here by default.
We add it to make a multi-system development easier for people that don't use
kafka and don't understand the concept of consumer groups.
# File lib/karafka/routing/consumer_group.rb, line 21
def initialize(name)
  @name = name
  @id = Karafka::App.config.consumer_mapper.call(name)
  @topics = []
end

Public Instance Methods

active?() click to toggle source

@return [Boolean] true if this consumer group should be active in our current process

# File lib/karafka/routing/consumer_group.rb, line 28
def active?
  Karafka::Server.consumer_groups.include?(name)
end
to_h() click to toggle source

Hashed version of consumer group that can be used for validation purposes @return [Hash] hash with consumer group attributes including serialized to hash topics inside of it.

# File lib/karafka/routing/consumer_group.rb, line 49
def to_h
  result = {
    topics: topics.map(&:to_h),
    id: id
  }

  Karafka::AttributesMap.consumer_group.each do |attribute|
    result[attribute] = public_send(attribute)
  end

  result
end
topic=(name, &block) click to toggle source

Builds a topic representation inside of a current consumer group route @param name [String, Symbol] name of topic to which we want to subscribe @param block [Proc] block that we want to evaluate in the topic context @return [Karafka::Routing::Topic] newly built topic instance

# File lib/karafka/routing/consumer_group.rb, line 36
def topic=(name, &block)
  topic = Topic.new(name, self)
  @topics << Proxy.new(topic, &block).target.tap(&:build)
  @topics.last
end