Sha256: 3ccf238f0e6d9d14252ded1e1c50775235cdb5f3d9b8842419a924fbe1195617

Contents?: true

Size: 1.59 KB

Versions: 6

Compression:

Stored size: 1.59 KB

Contents

# frozen_string_literal: true

module Karafka
  module Routing
    module Features
      class DeadLetterQueue < Base
        # This feature validation contracts
        module Contracts
          # Rules around dead letter queue settings
          class Topic < Karafka::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(:independent) { |val| [true, false].include?(val) }
              required(:max_retries) { |val| val.is_a?(Integer) && val >= 0 }
              required(:transactional) { |val| [true, false].include?(val) }
            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]
              topic_regexp = ::Karafka::Contracts::TOPIC_REGEXP

              # 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) && topic_regexp.match?(topic)

              [[%i[dead_letter_queue topic], :format]]
            end
          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/contracts/topic.rb
karafka-2.3.3 lib/karafka/routing/features/dead_letter_queue/contracts/topic.rb
karafka-2.3.2 lib/karafka/routing/features/dead_letter_queue/contracts/topic.rb
karafka-2.3.1 lib/karafka/routing/features/dead_letter_queue/contracts/topic.rb
karafka-2.3.0 lib/karafka/routing/features/dead_letter_queue/contracts/topic.rb
karafka-2.3.0.rc1 lib/karafka/routing/features/dead_letter_queue/contracts/topic.rb