Sha256: 56c4822a1e100f9f200a20276bb92ee0b16cb6a994749ccc8df33ed20643cccf

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

module Karafka
  module Routing
    # Default routes 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
    #
    # @example 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
    #
    # @example 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
    module Mapper
      class << self
        # @param topic [String, Symbol] topic
        # @return [String, Symbol] same topic as on input
        # @example
        #   incoming('topic_name') #=> 'topic_name'
        def incoming(topic)
          topic
        end

        # @param topic [String, Symbol] topic
        # @return [String, Symbol] same topic as on input
        # @example
        #   outgoing('topic_name') #=> 'topic_name'
        def outgoing(topic)
          topic
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
karafka-0.5.0.3 lib/karafka/routing/mapper.rb