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

Defined in:
lib/karafka/pro/routing/features/consumer_groups/inline_insights/topic.rb

Overview

Routing topic inline insights API

Instance Method Summary collapse

Instance Method Details

#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/inline_insights/topic.rb', line 43

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

#inline_insights(active = -1,, required: -1)) ⇒ Object

Parameters:

  • active (Boolean) (defaults to: -1,)

    should inline insights be activated

  • required (Boolean) (defaults to: -1))

    are the insights required to operate



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/karafka/pro/routing/features/consumer_groups/inline_insights/topic.rb', line 50

def inline_insights(active = -1, required: -1)
  # This weird style of checking allows us to activate inline insights in few ways:
  #   - inline_insights(true)
  #   - inline_insights(required: true)
  #   - inline_insights(required: false)
  #
  # In each of those cases inline insights will become active
  @inline_insights ||= begin
    config = Config.new(
      active: active == true || (active == -1 && required != -1),
      required: required == true
    )

    if config.active? && config.required?
      factory = lambda do |topic, partition|
        Pro::Processing::ConsumerGroups::Filters::InlineInsightsDelayer.new(topic, partition)
      end

      filter(factory)
    end

    config
  end
end