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

Constant Summary collapse

SUPPORTED_FEATURES =

Features we support in the OSS offering.

%i[
  active_job
  manual_offset_management
  dead_letter_queue
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStrategySelector

Returns a new instance of StrategySelector.



16
17
18
19
# File 'lib/karafka/processing/strategy_selector.rb', line 16

def initialize
  # We load them once for performance reasons not to do too many lookups
  @strategies = find_all
end

Instance Attribute Details

#strategiesObject (readonly)

Returns the value of attribute strategies.



7
8
9
# File 'lib/karafka/processing/strategy_selector.rb', line 7

def strategies
  @strategies
end

Instance Method Details

#find(topic) ⇒ Module

Returns module with proper strategy.

Parameters:

Returns:

  • (Module)

    module with proper strategy



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/karafka/processing/strategy_selector.rb', line 23

def find(topic)
  feature_set = SUPPORTED_FEATURES.map do |feature_name|
    topic.public_send("#{feature_name}?") ? feature_name : nil
  end

  feature_set.compact!

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