Class: Karafka::Processing::StrategySelector

Inherits:
Object
  • Object
show all
Defined in:
lib/karafka/processing/strategy_selector.rb

Overview

Selector of appropriate processing strategy matching topic combinations

Instance Method Summary collapse

Constructor Details

#initializeStrategySelector

Returns a new instance of StrategySelector.



7
8
9
10
11
12
13
# File 'lib/karafka/processing/strategy_selector.rb', line 7

def initialize
  # We load them once for performance reasons not to do too many lookups
  @available_strategies = Strategies
                          .constants
                          .delete_if { |k| k == :Base }
                          .map { |k| Strategies.const_get(k) }
end

Instance Method Details

#find(topic) ⇒ Module

Returns module with proper strategy.

Parameters:

Returns:

  • (Module)

    module with proper strategy



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/karafka/processing/strategy_selector.rb', line 17

def find(topic)
  feature_set = [
    topic.active_job? ? :active_job : nil,
    topic.manual_offset_management? ? :manual_offset_management : nil,
    topic.dead_letter_queue? ? :dead_letter_queue : nil
  ].compact

  @available_strategies.find do |strategy|
    strategy::FEATURES.sort == feature_set.sort
  end || raise(Errors::StrategyNotFoundError, topic.name)
end