Sha256: c13a7ea412241c249fdb13e41efe32c285cd2fd8d496ed706ebc2c90a6ed4cbd

Contents?: true

Size: 1.73 KB

Versions: 27

Compression:

Stored size: 1.73 KB

Contents

# frozen_string_literal: true

module Karafka
  module Responders
    # Topic describes a single topic on which we want to respond with responding requirements
    # @example Define topic (required by default)
    #   Karafka::Responders::Topic.new(:topic_name, {}) #=> #<Karafka::Responders::Topic...
    # @example Define optional topic
    #   Karafka::Responders::Topic.new(:topic_name, required: false)
    class Topic
      # Name of the topic on which we want to respond
      attr_reader :name

      # @param name [Symbol, String] name of a topic on which we want to respond
      # @param options [Hash] non-default options for this topic
      # @return [Karafka::Responders::Topic] topic description object
      def initialize(name, options)
        @name = name.to_s
        @options = options
      end

      # @return [Boolean] is this a required topic (if not, it is optional)
      def required?
        @options.key?(:required) ? @options[:required] : true
      end

      # @return [Boolean] was usage of this topic registered or not
      def registered?
        @options[:registered] == true
      end

      # @return [Class] Class to use to serialize messages for this topic
      def serializer
        @options[:serializer]
      end

      # @return [Boolean] do we want to use async producer. Defaults to false as the sync producer
      #   is safer and introduces less problems
      def async?
        @options.key?(:async) ? @options[:async] : false
      end

      # @return [Hash] hash with this topic attributes and options
      def to_h
        {
          name: name,
          required: required?,
          registered: registered?,
          serializer: serializer,
          async: async?
        }
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
karafka-1.4.15 lib/karafka/responders/topic.rb
karafka-1.4.14 lib/karafka/responders/topic.rb
karafka-1.4.13 lib/karafka/responders/topic.rb
karafka-1.4.12 lib/karafka/responders/topic.rb
karafka-1.4.11 lib/karafka/responders/topic.rb
karafka-1.4.10 lib/karafka/responders/topic.rb
karafka-1.4.9 lib/karafka/responders/topic.rb
karafka-1.4.8 lib/karafka/responders/topic.rb
karafka-1.4.7 lib/karafka/responders/topic.rb
karafka-1.4.6 lib/karafka/responders/topic.rb
karafka-1.4.5 lib/karafka/responders/topic.rb
karafka-1.4.4 lib/karafka/responders/topic.rb
karafka-1.4.3 lib/karafka/responders/topic.rb
karafka-1.4.2 lib/karafka/responders/topic.rb
karafka-1.4.1 lib/karafka/responders/topic.rb
karafka-1.4.0 lib/karafka/responders/topic.rb
karafka-1.4.0.rc2 lib/karafka/responders/topic.rb
karafka-1.4.0.rc1 lib/karafka/responders/topic.rb
karafka-1.3.7 lib/karafka/responders/topic.rb
karafka-1.3.6 lib/karafka/responders/topic.rb