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

Inherits:
Object
  • Object
show all
Defined in:
lib/karafka/pro/processing/consumer_groups/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.

Constant Summary collapse

SUPPORTED_FEATURES =

Strategies that we support in the Pro offering They can be combined

%i[
  active_job
  long_running_job
  manual_offset_management
  virtual_partitions
  dead_letter_queue
  filtering
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStrategySelector

Initializes the strategy selector and preloads all strategies



55
56
57
58
59
# File 'lib/karafka/pro/processing/consumer_groups/strategy_selector.rb', line 55

def initialize
  # Preload the strategies
  # 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.



42
43
44
# File 'lib/karafka/pro/processing/consumer_groups/strategy_selector.rb', line 42

def strategies
  @strategies
end

Instance Method Details

#find(topic) ⇒ Module

Returns module with proper strategy.

Parameters:

Returns:

  • (Module)

    module with proper strategy



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/karafka/pro/processing/consumer_groups/strategy_selector.rb', line 64

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

  feature_set.compact!
  feature_set.sort!

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