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

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

Overview

Routing topic inline insights API

Instance Method Summary collapse

Instance Method Details

#initializeObject

This method calls the parent class initializer and then sets up the extra instance variable to nil. The explicit initialization to nil is included as an optimization for Ruby’s object shapes system, which improves memory layout and access performance.



34
35
36
37
# File 'lib/karafka/pro/routing/features/inline_insights/topic.rb', line 34

def initialize(...)
  super
  @inline_insights = nil
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



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/karafka/pro/routing/features/inline_insights/topic.rb', line 41

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::Filters::InlineInsightsDelayer.new(topic, partition)
      end

      filter(factory)
    end

    config
  end
end