Class: Karafka::Pro::Processing::StrategySelector

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

Overview

Selector of appropriate processing strategy matching topic combinations When using Karafka Pro, there is a different set of strategies than for regular, as there are different features.

Instance Method Summary collapse

Constructor Details

#initializeStrategySelector

Returns a new instance of StrategySelector.



21
22
23
24
25
26
27
# File 'lib/karafka/pro/processing/strategy_selector.rb', line 21

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



32
33
34
35
36
37
38
# File 'lib/karafka/pro/processing/strategy_selector.rb', line 32

def find(topic)
  feature_set = features_map(topic)

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