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)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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



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

def initialize(name, options)
  @name = name.to_s
  @options = options
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

#async?Boolean



39
40
41
# File 'lib/karafka/responders/topic.rb', line 39

def async?
  @options.key?(:async) ? @options[:async] : false
end

#registered?Boolean



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

def registered?
  @options[:registered] == true
end

#required?Boolean



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

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

#serializerClass



33
34
35
# File 'lib/karafka/responders/topic.rb', line 33

def serializer
  @options[:serializer]
end

#to_hHash



44
45
46
47
48
49
50
51
52
# File 'lib/karafka/responders/topic.rb', line 44

def to_h
  {
    name: name,
    required: required?,
    registered: registered?,
    serializer: serializer,
    async: async?
  }
end