Module: Karafka::Routing::Features::ManualOffsetManagement::Topic

Defined in:
lib/karafka/routing/features/manual_offset_management/topic.rb

Overview

Topic extensions to be able to manage manual offset management settings

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.



13
14
15
16
# File 'lib/karafka/routing/features/manual_offset_management/topic.rb', line 13

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

#manual_offset_management(active = false) ⇒ Config

Note:

Since this feature supports only one setting (active), we can use the old API

where the boolean would be an argument

Parameters:

  • active (Boolean) (defaults to: false)

    should we stop managing the offset in Karafka and make the user responsible for marking messages as consumed.

Returns:



24
25
26
# File 'lib/karafka/routing/features/manual_offset_management/topic.rb', line 24

def manual_offset_management(active = false)
  @manual_offset_management ||= Config.new(active: active)
end

#manual_offset_management?Boolean

Returns is manual offset management enabled for a given topic.

Returns:

  • (Boolean)

    is manual offset management enabled for a given topic



29
30
31
# File 'lib/karafka/routing/features/manual_offset_management/topic.rb', line 29

def manual_offset_management?
  manual_offset_management.active?
end

#to_hHash

Returns topic with all its native configuration options plus manual offset management namespace settings.

Returns:

  • (Hash)

    topic with all its native configuration options plus manual offset management namespace settings



35
36
37
38
39
# File 'lib/karafka/routing/features/manual_offset_management/topic.rb', line 35

def to_h
  super.merge(
    manual_offset_management: manual_offset_management.to_h
  ).freeze
end