Module: Karafka::Pro::Routing::Features::DeadLetterQueue::Topic

Defined in:
lib/karafka/pro/routing/features/dead_letter_queue/topic.rb

Overview

Expansions to the topic API in DLQ

Instance Method Summary collapse

Instance Method Details

#dead_letter_queue(strategy: nil, **args) ⇒ Object

(same as in OSS) should be applied

Parameters:

  • strategy (#call, nil) (defaults to: nil)

    Strategy we want to use or nil if a default strategy

  • args (Hash)

    Pro DLQ arguments

Options Hash (**args):

  • :topic (String, nil)

    name of the dead letter queue topic

  • :max_retries (Integer)

    maximum number of retries before dispatch to DLQ

  • :independent (Boolean)

    whether DLQ runs independently



28
29
30
31
32
33
34
35
36
37
# File 'lib/karafka/pro/routing/features/dead_letter_queue/topic.rb', line 28

def dead_letter_queue(strategy: nil, **args)
  return @dead_letter_queue if @dead_letter_queue

  super(**args).tap do |config|
    # If explicit strategy is not provided, use the default approach from OSS
    config.strategy = strategy || lambda do |_errors_tracker, attempt|
      attempt > config.max_retries ? :dispatch : :retry
    end
  end
end

#initializeObject

This method calls the parent class initializer and then sets up the extra instance variable to nil. The explicit initialization to nil is included as an optimization for Ruby’s object shapes system, which improves memory layout and access performance.



17
18
19
20
# File 'lib/karafka/pro/routing/features/dead_letter_queue/topic.rb', line 17

def initialize(...)
  super
  @dead_letter_queue = nil
end