Class: Karafka::Responders::Topic

Inherits:
Object
  • Object
show all
Defined in:
lib/karafka/responders/topic.rb

Overview

Topic describes a single topic on which we want to respond with responding requirements

Examples:

Define topic (required by default)

Karafka::Responders::Topic.new(:topic_name, {}) #=> #<Karafka::Responders::Topic...

Define optional topic

Karafka::Responders::Topic.new(:topic_name, required: false)

Define topic that on which we want to respond multiple times

Karafka::Responders::Topic.new(:topic_name, multiple_usage: true)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ Karafka::Responders::Topic

Returns topic description object.

Parameters:

  • name (Symbol, String)

    name of a topic on which we want to respond

  • options (Hash)

    non-default options for this topic



17
18
19
20
21
# File 'lib/karafka/responders/topic.rb', line 17

def initialize(name, options)
  @name = name.to_s
  @options = options
  validate!
end

Instance Attribute Details

#nameObject (readonly)

Name of the topic on which we want to respond



12
13
14
# File 'lib/karafka/responders/topic.rb', line 12

def name
  @name
end

Instance Method Details

#multiple_usage?Boolean

Returns do we expect to use it multiple times in a single respond flow.

Returns:

  • (Boolean)

    do we expect to use it multiple times in a single respond flow



29
30
31
# File 'lib/karafka/responders/topic.rb', line 29

def multiple_usage?
  @options[:multiple_usage] || false
end

#required?Boolean

Returns is this a required topic (if not, it is optional).

Returns:

  • (Boolean)

    is this a required topic (if not, it is optional)



24
25
26
# File 'lib/karafka/responders/topic.rb', line 24

def required?
  @options.key?(:required) ? @options[:required] : true
end