Module: Karafka::Pro::Processing::Strategies::Lrj::Mom

Includes:
Default
Included in:
Aj::LrjMom, MomVp
Defined in:
lib/karafka/pro/processing/strategies/lrj/mom.rb

Overview

Long-Running Job enabled Manual offset management enabled

Constant Summary collapse

FEATURES =

Features for this strategy

%i[
  long_running_job
  manual_offset_management
].freeze

Instance Method Summary collapse

Methods included from Default

#handle_before_consume, #handle_before_schedule_tick, #handle_consume, #handle_tick, #mark_as_consumed, #mark_as_consumed!, #mark_in_transaction, #store_offset_metadata, #transaction

Methods included from Karafka::Processing::Strategies::Default

#commit_offsets, #commit_offsets!, #handle_before_consume, #handle_consume, #handle_eofed, #handle_idle, #handle_initialized, #handle_shutdown, #mark_as_consumed, #mark_as_consumed!

Methods included from Karafka::Processing::Strategies::Base

#handle_before_consume, #handle_consume, #handle_idle, #handle_shutdown

Instance Method Details

#handle_after_consumeObject

No offset management, aside from that typical LRJ



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/karafka/pro/processing/strategies/lrj/mom.rb', line 43

def handle_after_consume
  coordinator.on_finished do |last_group_message|
    if coordinator.success?
      coordinator.pause_tracker.reset

      return if coordinator.manual_pause?

      unless revoked? || coordinator.manual_seek?
        seek(last_group_message.offset + 1, false)
      end

      resume
    else
      retry_after_pause
    end
  end
end

#handle_before_schedule_consumeObject

We always need to pause prior to doing any jobs for LRJ



32
33
34
35
36
37
38
39
40
# File 'lib/karafka/pro/processing/strategies/lrj/mom.rb', line 32

def handle_before_schedule_consume
  super

  # This ensures that when running LRJ with VP, things operate as expected run only
  # once for all the virtual partitions collectively
  coordinator.on_enqueued do
    pause(:consecutive, Strategies::Lrj::Default::MAX_PAUSE_TIME, false)
  end
end

#handle_revokedObject

We do not un-pause on revokations for LRJ



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/karafka/pro/processing/strategies/lrj/mom.rb', line 62

def handle_revoked
  coordinator.on_revoked do
    coordinator.revoke
  end

  Karafka.monitor.instrument('consumer.revoke', caller: self)
  Karafka.monitor.instrument('consumer.revoked', caller: self) do
    revoked
  end
ensure
  coordinator.decrement(:revoked)
end