Sha256: ce04d6a0d9e26baad7e577ca1289bd7f0e43afb8be4c6d8692aaef0c417dcf71

Contents?: true

Size: 1.26 KB

Versions: 32

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

module Karafka
  module Routing
    module Features
      class DeadLetterQueue < Base
        # Rules around dead letter queue settings
        class Contract < Contracts::Base
          configure do |config|
            config.error_messages = YAML.safe_load(
              File.read(
                File.join(Karafka.gem_root, 'config', 'locales', 'errors.yml')
              )
            ).fetch('en').fetch('validations').fetch('topic')
          end

          nested :dead_letter_queue do
            required(:active) { |val| [true, false].include?(val) }
            required(:max_retries) { |val| val.is_a?(Integer) && val >= 0 }
          end

          # Validate topic name only if dlq is active
          virtual do |data, errors|
            next unless errors.empty?

            dead_letter_queue = data[:dead_letter_queue]

            next unless dead_letter_queue[:active]

            topic = dead_letter_queue[:topic]

            # When topic is set to false, it means we just want to skip dispatch on DLQ
            next if topic == false
            next if topic.is_a?(String) && Contracts::TOPIC_REGEXP.match?(topic)

            [[%i[dead_letter_queue topic], :format]]
          end
        end
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
karafka-2.1.13 lib/karafka/routing/features/dead_letter_queue/contract.rb
karafka-2.1.12 lib/karafka/routing/features/dead_letter_queue/contract.rb
karafka-2.1.11 lib/karafka/routing/features/dead_letter_queue/contract.rb
karafka-2.1.10 lib/karafka/routing/features/dead_letter_queue/contract.rb
karafka-2.1.9 lib/karafka/routing/features/dead_letter_queue/contract.rb
karafka-2.1.8 lib/karafka/routing/features/dead_letter_queue/contract.rb
karafka-2.1.7 lib/karafka/routing/features/dead_letter_queue/contract.rb
karafka-2.1.6 lib/karafka/routing/features/dead_letter_queue/contract.rb
karafka-2.1.5 lib/karafka/routing/features/dead_letter_queue/contract.rb
karafka-2.1.5.beta1 lib/karafka/routing/features/dead_letter_queue/contract.rb
karafka-2.1.4 lib/karafka/routing/features/dead_letter_queue/contract.rb
karafka-2.1.3 lib/karafka/routing/features/dead_letter_queue/contract.rb
karafka-2.1.2 lib/karafka/routing/features/dead_letter_queue/contract.rb
karafka-2.1.1 lib/karafka/routing/features/dead_letter_queue/contract.rb
karafka-2.1.0 lib/karafka/routing/features/dead_letter_queue/contract.rb
karafka-2.0.41 lib/karafka/routing/features/dead_letter_queue/contract.rb
karafka-2.0.40 lib/karafka/routing/features/dead_letter_queue/contract.rb
karafka-2.0.39 lib/karafka/routing/features/dead_letter_queue/contract.rb
karafka-2.0.38 lib/karafka/routing/features/dead_letter_queue/contract.rb
karafka-2.0.37 lib/karafka/routing/features/dead_letter_queue/contract.rb