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

Defined in:
lib/karafka/pro/routing/features/consumer_groups/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



54
55
56
57
58
59
60
61
62
63
# File 'lib/karafka/pro/routing/features/consumer_groups/dead_letter_queue/topic.rb', line 54

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 sets up the extra instance variable to nil before calling the parent class initializer. The explicit initialization to nil is included as an optimization for Ruby’s object shapes system, which improves memory layout and access performance.



43
44
45
46
# File 'lib/karafka/pro/routing/features/consumer_groups/dead_letter_queue/topic.rb', line 43

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