Sha256: 9ba6fb9a77b3b543181b5672a9e05b66e4b3f529ff6aeb14bd182793a0634efb

Contents?: true

Size: 1.75 KB

Versions: 6

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true

module Karafka
  module Routing
    module Features
      class DeadLetterQueue < Base
        # DLQ topic extensions
        module Topic
          # After how many retries should be move data to DLQ
          DEFAULT_MAX_RETRIES = 3

          private_constant :DEFAULT_MAX_RETRIES

          # @param max_retries [Integer] after how many retries should we move data to dlq
          # @param topic [String, false] where the messages should be moved if failing or false
          #   if we do not want to move it anywhere and just skip
          # @param independent [Boolean] needs to be true in order for each marking as consumed
          #   in a retry flow to reset the errors counter
          # @param transactional [Boolean] if applicable, should transaction be used to move
          #   given message to the dead-letter topic and mark it as consumed.
          # @return [Config] defined config
          def dead_letter_queue(
            max_retries: DEFAULT_MAX_RETRIES,
            topic: nil,
            independent: false,
            transactional: true
          )
            @dead_letter_queue ||= Config.new(
              active: !topic.nil?,
              max_retries: max_retries,
              topic: topic,
              independent: independent,
              transactional: transactional
            )
          end

          # @return [Boolean] is the dlq active or not
          def dead_letter_queue?
            dead_letter_queue.active?
          end

          # @return [Hash] topic with all its native configuration options plus dlq settings
          def to_h
            super.merge(
              dead_letter_queue: dead_letter_queue.to_h
            ).freeze
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
karafka-2.3.4 lib/karafka/routing/features/dead_letter_queue/topic.rb
karafka-2.3.3 lib/karafka/routing/features/dead_letter_queue/topic.rb
karafka-2.3.2 lib/karafka/routing/features/dead_letter_queue/topic.rb
karafka-2.3.1 lib/karafka/routing/features/dead_letter_queue/topic.rb
karafka-2.3.0 lib/karafka/routing/features/dead_letter_queue/topic.rb
karafka-2.3.0.rc1 lib/karafka/routing/features/dead_letter_queue/topic.rb