Module: Karafka::Routing::TopicMapper

Defined in:
lib/karafka/routing/topic_mapper.rb

Overview

Default topic mapper that does not remap things Mapper can be used for Kafka providers that require namespaced topic names. Instead of being provider dependent, we can then define mapper and use internally “pure” topic names in routes and responders

Examples:

Mapper for mapping prefixed topics

module MyMapper
  PREFIX = "my_user_name."

  def incoming(topic)
    topic.to_s.gsub(PREFIX, '')
  end

  def outgoing(topic)
    "#{PREFIX}#{topic}"
  end
end

Mapper for replacing “.” with “_” in topic names

module MyMapper
  PREFIX = "my_user_name."

  def incoming(topic)
    topic.to_s.gsub('.', '_')
  end

  def outgoing(topic)
    topic.to_s.gsub('_', '.')
  end
end

Class Method Summary collapse

Class Method Details

.incoming(topic) ⇒ String, Symbol

Returns same topic as on input.

Examples:

incoming('topic_name') #=> 'topic_name'

Parameters:

  • topic (String, Symbol)

    topic

Returns:

  • (String, Symbol)

    same topic as on input



41
42
43
# File 'lib/karafka/routing/topic_mapper.rb', line 41

def incoming(topic)
  topic
end

.outgoing(topic) ⇒ String, Symbol

Returns same topic as on input.

Examples:

outgoing('topic_name') #=> 'topic_name'

Parameters:

  • topic (String, Symbol)

    topic

Returns:

  • (String, Symbol)

    same topic as on input



49
50
51
# File 'lib/karafka/routing/topic_mapper.rb', line 49

def outgoing(topic)
  topic
end