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

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
# 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

Returns do we want to use async producer. Defaults to false as the sync producer is safer and introduces less problems.

Returns:

  • (Boolean)

    do we want to use async producer. Defaults to false as the sync producer is safer and introduces less problems



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

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

#registered?Boolean

Returns was usage of this topic registered or not.

Returns:

  • (Boolean)

    was usage of this topic registered or not



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

def registered?
  @options[:registered] == true
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)



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

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

#serializerClass

Returns Class to use to serialize messages for this topic.

Returns:

  • (Class)

    Class to use to serialize messages for this topic



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

def serializer
  @options[:serializer]
end

#to_hHash

Returns hash with this topic attributes and options.

Returns:

  • (Hash)

    hash with this topic attributes and options



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