class Karafka::Routing::Topic
It is a part of Karafka’s DSL
It belongs to a consumer group as from 0.6 all the topics can work in the same consumer group
Topic stores all the details on how we should interact with Kafka given topic
def build
everywhere except Karafka server command, those would not be initialized on time - for
not yet specified. This is need to be done (cannot be lazy loaded on first use) because
Initializes default values for all the options that support defaults if their values are
def build Karafka::AttributesMap.topic.each { |attr| send(attr) } consumer&.topic = self self end
def initialize(name, consumer_group)
-
consumer_group
(Karafka::Routing::ConsumerGroup
) -- owning consumer group of this topic -
name
(String, Symbol
) -- of a topic on which we want to listen
def initialize(name, consumer_group) @name = name.to_s @consumer_group = consumer_group @attributes = {} # @note We use identifier related to the consumer group that owns a topic, because from # Karafka 0.6 we can handle multiple Kafka instances with the same process and we can # have same topic name across mutliple Kafkas @id = "#{consumer_group.id}_#{@name}" end
def responder
-
(Class, nil)
- Class (not an instance) of a responder that should respond from
def responder @responder ||= Karafka::Responders::Builder.new(consumer).build end
def to_h
- Note: - This is being used when we validate the consumer_group and its topics
Returns:
-
(Hash)
- hash with all the topic attributes
def to_h map = Karafka::AttributesMap.topic.map do |attribute| [attribute, public_send(attribute)] end Hash[map].merge!( id: id, consumer: consumer ) end