Sha256: 4707a3fc96d573389e1f5396af906f926f33e7c2024ecc4301f37dfc0909ee83

Contents?: true

Size: 1.45 KB

Versions: 24

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true

module Karafka
  module Routing
    # 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
    #
    # @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 TopicMapper
      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

24 entries across 24 versions & 1 rubygems

Version Path
karafka-1.2.13 lib/karafka/routing/topic_mapper.rb
karafka-1.2.12 lib/karafka/routing/topic_mapper.rb
karafka-1.2.11 lib/karafka/routing/topic_mapper.rb
karafka-1.2.10 lib/karafka/routing/topic_mapper.rb
karafka-1.2.9 lib/karafka/routing/topic_mapper.rb
karafka-1.2.8 lib/karafka/routing/topic_mapper.rb
karafka-1.2.7 lib/karafka/routing/topic_mapper.rb
karafka-1.2.6 lib/karafka/routing/topic_mapper.rb
karafka-1.2.5 lib/karafka/routing/topic_mapper.rb
karafka-1.2.4 lib/karafka/routing/topic_mapper.rb
karafka-1.2.3 lib/karafka/routing/topic_mapper.rb
karafka-1.2.2 lib/karafka/routing/topic_mapper.rb
karafka-1.2.1 lib/karafka/routing/topic_mapper.rb
karafka-1.2.0 lib/karafka/routing/topic_mapper.rb
karafka-1.2.0.beta4 lib/karafka/routing/topic_mapper.rb
karafka-1.2.0.beta3 lib/karafka/routing/topic_mapper.rb
karafka-1.2.0.beta2 lib/karafka/routing/topic_mapper.rb
karafka-1.2.0.beta1 lib/karafka/routing/topic_mapper.rb
karafka-1.1.2 lib/karafka/routing/topic_mapper.rb
karafka-1.1.1 lib/karafka/routing/topic_mapper.rb