karafka 2.0.38 → 2.0.40
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/.github/workflows/ci.yml +1 -1
- data/.ruby-version +1 -1
- data/CHANGELOG.md +34 -0
- data/Gemfile.lock +4 -4
- data/bin/integrations +1 -1
- data/config/locales/errors.yml +0 -7
- data/config/locales/pro_errors.yml +18 -0
- data/lib/karafka/base_consumer.rb +35 -55
- data/lib/karafka/connection/listener.rb +15 -10
- data/lib/karafka/errors.rb +0 -3
- data/lib/karafka/instrumentation/logger_listener.rb +44 -3
- data/lib/karafka/instrumentation/notifications.rb +4 -0
- data/lib/karafka/messages/builders/batch_metadata.rb +6 -5
- data/lib/karafka/messages/builders/messages.rb +3 -1
- data/lib/karafka/messages/messages.rb +5 -0
- data/lib/karafka/pro/active_job/consumer.rb +10 -1
- data/lib/karafka/pro/processing/coordinator.rb +13 -4
- data/lib/karafka/pro/processing/filters/base.rb +61 -0
- data/lib/karafka/pro/processing/filters/delayer.rb +70 -0
- data/lib/karafka/pro/processing/filters/expirer.rb +51 -0
- data/lib/karafka/pro/processing/filters/throttler.rb +84 -0
- data/lib/karafka/pro/processing/filters_applier.rb +100 -0
- data/lib/karafka/pro/processing/jobs_builder.rb +7 -3
- data/lib/karafka/pro/processing/scheduler.rb +24 -7
- data/lib/karafka/pro/processing/strategies/aj/dlq_ftr_lrj_mom.rb +68 -0
- data/lib/karafka/pro/processing/strategies/aj/dlq_ftr_lrj_mom_vp.rb +74 -0
- data/lib/karafka/pro/processing/strategies/aj/dlq_ftr_mom.rb +72 -0
- data/lib/karafka/pro/processing/strategies/aj/dlq_ftr_mom_vp.rb +76 -0
- data/lib/karafka/pro/processing/strategies/aj/dlq_lrj_mom.rb +62 -0
- data/lib/karafka/pro/processing/strategies/aj/dlq_lrj_mom_vp.rb +68 -0
- data/lib/karafka/pro/processing/strategies/aj/dlq_mom.rb +64 -0
- data/lib/karafka/pro/processing/strategies/aj/dlq_mom_vp.rb +69 -0
- data/lib/karafka/pro/processing/strategies/aj/ftr_lrj_mom.rb +38 -0
- data/lib/karafka/pro/processing/strategies/aj/ftr_lrj_mom_vp.rb +64 -0
- data/lib/karafka/pro/processing/strategies/aj/ftr_mom.rb +38 -0
- data/lib/karafka/pro/processing/strategies/aj/ftr_mom_vp.rb +58 -0
- data/lib/karafka/pro/processing/strategies/{dlq_lrj_vp.rb → aj/lrj_mom.rb} +14 -13
- data/lib/karafka/pro/processing/strategies/aj/lrj_mom_vp.rb +77 -0
- data/lib/karafka/pro/processing/strategies/aj/mom.rb +36 -0
- data/lib/karafka/pro/processing/strategies/aj/mom_vp.rb +52 -0
- data/lib/karafka/pro/processing/strategies/dlq/default.rb +131 -0
- data/lib/karafka/pro/processing/strategies/dlq/ftr.rb +61 -0
- data/lib/karafka/pro/processing/strategies/dlq/ftr_lrj.rb +75 -0
- data/lib/karafka/pro/processing/strategies/dlq/ftr_lrj_mom.rb +74 -0
- data/lib/karafka/pro/processing/strategies/{mom.rb → dlq/ftr_lrj_vp.rb} +16 -19
- data/lib/karafka/pro/processing/strategies/dlq/ftr_mom.rb +73 -0
- data/lib/karafka/pro/processing/strategies/dlq/ftr_vp.rb +39 -0
- data/lib/karafka/pro/processing/strategies/dlq/lrj.rb +63 -0
- data/lib/karafka/pro/processing/strategies/dlq/lrj_mom.rb +66 -0
- data/lib/karafka/pro/processing/strategies/dlq/lrj_vp.rb +38 -0
- data/lib/karafka/pro/processing/strategies/dlq/mom.rb +67 -0
- data/lib/karafka/pro/processing/strategies/dlq/vp.rb +40 -0
- data/lib/karafka/pro/processing/strategies/ftr/default.rb +104 -0
- data/lib/karafka/pro/processing/strategies/ftr/vp.rb +40 -0
- data/lib/karafka/pro/processing/strategies/lrj/default.rb +85 -0
- data/lib/karafka/pro/processing/strategies/lrj/ftr.rb +69 -0
- data/lib/karafka/pro/processing/strategies/lrj/ftr_mom.rb +67 -0
- data/lib/karafka/pro/processing/strategies/{vp.rb → lrj/ftr_vp.rb} +15 -13
- data/lib/karafka/pro/processing/strategies/lrj/mom.rb +78 -0
- data/lib/karafka/pro/processing/strategies/{aj_lrj_mom.rb → lrj/vp.rb} +13 -12
- data/lib/karafka/pro/processing/strategies/mom/default.rb +46 -0
- data/lib/karafka/pro/processing/strategies/mom/ftr.rb +53 -0
- data/lib/karafka/pro/processing/strategies/vp/default.rb +53 -0
- data/lib/karafka/pro/processing/{strategies/lrj_vp.rb → strategies.rb} +1 -13
- data/lib/karafka/pro/processing/strategy_selector.rb +44 -18
- data/lib/karafka/pro/{processing/strategies/aj_mom.rb → routing/features/delaying/config.rb} +7 -13
- data/lib/karafka/pro/routing/features/delaying/contract.rb +38 -0
- data/lib/karafka/pro/routing/features/delaying/topic.rb +59 -0
- data/lib/karafka/pro/routing/features/delaying.rb +29 -0
- data/lib/karafka/pro/routing/features/expiring/config.rb +27 -0
- data/lib/karafka/pro/routing/features/expiring/contract.rb +38 -0
- data/lib/karafka/pro/routing/features/expiring/topic.rb +59 -0
- data/lib/karafka/pro/routing/features/expiring.rb +27 -0
- data/lib/karafka/pro/routing/features/filtering/config.rb +40 -0
- data/lib/karafka/pro/routing/features/filtering/contract.rb +41 -0
- data/lib/karafka/pro/routing/features/filtering/topic.rb +51 -0
- data/lib/karafka/pro/routing/features/filtering.rb +27 -0
- data/lib/karafka/pro/routing/features/long_running_job/contract.rb +1 -1
- data/lib/karafka/pro/routing/features/throttling/config.rb +32 -0
- data/lib/karafka/pro/routing/features/throttling/contract.rb +41 -0
- data/lib/karafka/pro/routing/features/throttling/topic.rb +69 -0
- data/lib/karafka/pro/routing/features/throttling.rb +30 -0
- data/lib/karafka/processing/coordinator.rb +60 -30
- data/lib/karafka/processing/coordinators_buffer.rb +5 -1
- data/lib/karafka/processing/executor.rb +37 -21
- data/lib/karafka/processing/executors_buffer.rb +10 -26
- data/lib/karafka/processing/jobs/consume.rb +2 -4
- data/lib/karafka/processing/jobs/idle.rb +24 -0
- data/lib/karafka/processing/jobs_builder.rb +2 -3
- data/lib/karafka/processing/result.rb +5 -0
- data/lib/karafka/processing/strategies/aj_dlq_mom.rb +1 -1
- data/lib/karafka/processing/strategies/base.rb +5 -0
- data/lib/karafka/processing/strategies/default.rb +50 -0
- data/lib/karafka/processing/strategies/dlq.rb +13 -4
- data/lib/karafka/processing/strategies/dlq_mom.rb +8 -3
- data/lib/karafka/processing/strategy_selector.rb +27 -10
- data/lib/karafka/version.rb +1 -1
- data/renovate.json +6 -0
- data.tar.gz.sig +0 -0
- metadata +66 -22
- metadata.gz.sig +0 -0
- data/lib/karafka/pro/processing/strategies/aj_dlq_lrj_mom.rb +0 -42
- data/lib/karafka/pro/processing/strategies/aj_dlq_lrj_mom_vp.rb +0 -70
- data/lib/karafka/pro/processing/strategies/aj_dlq_mom.rb +0 -62
- data/lib/karafka/pro/processing/strategies/aj_dlq_mom_vp.rb +0 -68
- data/lib/karafka/pro/processing/strategies/aj_lrj_mom_vp.rb +0 -75
- data/lib/karafka/pro/processing/strategies/aj_mom_vp.rb +0 -62
- data/lib/karafka/pro/processing/strategies/dlq.rb +0 -120
- data/lib/karafka/pro/processing/strategies/dlq_lrj.rb +0 -65
- data/lib/karafka/pro/processing/strategies/dlq_lrj_mom.rb +0 -62
- data/lib/karafka/pro/processing/strategies/dlq_mom.rb +0 -62
- data/lib/karafka/pro/processing/strategies/dlq_vp.rb +0 -37
- data/lib/karafka/pro/processing/strategies/lrj.rb +0 -83
- data/lib/karafka/pro/processing/strategies/lrj_mom.rb +0 -73
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This Karafka component is a Pro component under a commercial license.
|
4
|
+
# This Karafka component is NOT licensed under LGPL.
|
5
|
+
#
|
6
|
+
# All of the commercial components are present in the lib/karafka/pro directory of this
|
7
|
+
# repository and their usage requires commercial license agreement.
|
8
|
+
#
|
9
|
+
# Karafka has also commercial-friendly license, commercial support and commercial components.
|
10
|
+
#
|
11
|
+
# By sending a pull request to the pro components, you are agreeing to transfer the copyright of
|
12
|
+
# your code to Maciej Mensfeld.
|
13
|
+
|
14
|
+
module Karafka
|
15
|
+
module Pro
|
16
|
+
module Processing
|
17
|
+
module Strategies
|
18
|
+
module Dlq
|
19
|
+
# Strategy for supporting DLQ with Mom enabled
|
20
|
+
module Mom
|
21
|
+
# The broken message lookup is the same in this scenario
|
22
|
+
include Strategies::Dlq::Default
|
23
|
+
|
24
|
+
# Features for this strategy
|
25
|
+
FEATURES = %i[
|
26
|
+
dead_letter_queue
|
27
|
+
manual_offset_management
|
28
|
+
].freeze
|
29
|
+
|
30
|
+
# When manual offset management is on, we do not mark anything as consumed
|
31
|
+
# automatically and we rely on the user to figure things out
|
32
|
+
def handle_after_consume
|
33
|
+
coordinator.on_finished do
|
34
|
+
return if revoked?
|
35
|
+
|
36
|
+
if coordinator.success?
|
37
|
+
coordinator.pause_tracker.reset
|
38
|
+
elsif coordinator.pause_tracker.attempt <= topic.dead_letter_queue.max_retries
|
39
|
+
retry_after_pause
|
40
|
+
# If we've reached number of retries that we could, we need to skip the first
|
41
|
+
# message that was not marked as consumed, pause and continue, while also moving
|
42
|
+
# this message to the dead topic.
|
43
|
+
#
|
44
|
+
# For a Mom setup, this means, that user has to manage the checkpointing by
|
45
|
+
# himself. If no checkpointing is ever done, we end up with an endless loop.
|
46
|
+
else
|
47
|
+
# We reset the pause to indicate we will now consider it as "ok".
|
48
|
+
coordinator.pause_tracker.reset
|
49
|
+
|
50
|
+
skippable_message, marked = find_skippable_message
|
51
|
+
dispatch_to_dlq(skippable_message) if dispatch_to_dlq?
|
52
|
+
|
53
|
+
# Move beyond the broken message
|
54
|
+
if marked
|
55
|
+
pause(coordinator.seek_offset, nil, false)
|
56
|
+
else
|
57
|
+
pause(skippable_message.offset + 1, nil, false)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This Karafka component is a Pro component under a commercial license.
|
4
|
+
# This Karafka component is NOT licensed under LGPL.
|
5
|
+
#
|
6
|
+
# All of the commercial components are present in the lib/karafka/pro directory of this
|
7
|
+
# repository and their usage requires commercial license agreement.
|
8
|
+
#
|
9
|
+
# Karafka has also commercial-friendly license, commercial support and commercial components.
|
10
|
+
#
|
11
|
+
# By sending a pull request to the pro components, you are agreeing to transfer the copyright of
|
12
|
+
# your code to Maciej Mensfeld.
|
13
|
+
|
14
|
+
module Karafka
|
15
|
+
module Pro
|
16
|
+
module Processing
|
17
|
+
module Strategies
|
18
|
+
module Dlq
|
19
|
+
# Dead Letter Queue enabled
|
20
|
+
# Virtual Partitions enabled
|
21
|
+
#
|
22
|
+
# In general because we collapse processing in virtual partitions to one on errors, there
|
23
|
+
# is no special action that needs to be taken because we warranty that even with VPs
|
24
|
+
# on errors a retry collapses into a single state and from this single state we can
|
25
|
+
# mark as consumed the message that we are moving to the DLQ.
|
26
|
+
module Vp
|
27
|
+
# Features for this strategy
|
28
|
+
FEATURES = %i[
|
29
|
+
dead_letter_queue
|
30
|
+
virtual_partitions
|
31
|
+
].freeze
|
32
|
+
|
33
|
+
include Strategies::Dlq::Default
|
34
|
+
include Strategies::Vp::Default
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This Karafka component is a Pro component under a commercial license.
|
4
|
+
# This Karafka component is NOT licensed under LGPL.
|
5
|
+
#
|
6
|
+
# All of the commercial components are present in the lib/karafka/pro directory of this
|
7
|
+
# repository and their usage requires commercial license agreement.
|
8
|
+
#
|
9
|
+
# Karafka has also commercial-friendly license, commercial support and commercial components.
|
10
|
+
#
|
11
|
+
# By sending a pull request to the pro components, you are agreeing to transfer the copyright of
|
12
|
+
# your code to Maciej Mensfeld.
|
13
|
+
|
14
|
+
module Karafka
|
15
|
+
module Pro
|
16
|
+
module Processing
|
17
|
+
module Strategies
|
18
|
+
# Filtering related init strategies
|
19
|
+
module Ftr
|
20
|
+
# Only filtering enabled
|
21
|
+
module Default
|
22
|
+
include Strategies::Default
|
23
|
+
|
24
|
+
# Just filtering enabled
|
25
|
+
FEATURES = %i[
|
26
|
+
filtering
|
27
|
+
].freeze
|
28
|
+
|
29
|
+
# Empty run when running on idle means we need to filter
|
30
|
+
def handle_idle
|
31
|
+
handle_post_filtering
|
32
|
+
end
|
33
|
+
|
34
|
+
# Standard flow without any features
|
35
|
+
def handle_after_consume
|
36
|
+
coordinator.on_finished do |last_group_message|
|
37
|
+
return if revoked?
|
38
|
+
|
39
|
+
if coordinator.success?
|
40
|
+
coordinator.pause_tracker.reset
|
41
|
+
|
42
|
+
# Do not mark last message if pause happened. This prevents a scenario where
|
43
|
+
# pause is overridden upon rebalance by marking
|
44
|
+
return if coordinator.manual_pause?
|
45
|
+
|
46
|
+
mark_as_consumed(last_group_message)
|
47
|
+
|
48
|
+
handle_post_filtering
|
49
|
+
else
|
50
|
+
retry_after_pause
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Throttles by pausing for an expected time period if throttling is needed or seeks
|
56
|
+
# in case the throttle expired. Throttling may expire because we throttle before
|
57
|
+
# processing starts and we need to compensate for processing time. It may turn out
|
58
|
+
# that we don't have to pause but we need to move the offset because we skipped some
|
59
|
+
# messages due to throttling filtering.
|
60
|
+
# @return [Boolean] was any form of throttling operations (pause or seek) needed
|
61
|
+
def handle_post_filtering
|
62
|
+
filter = coordinator.filter
|
63
|
+
|
64
|
+
# We pick the timeout before the action because every action takes time. This time
|
65
|
+
# may then mean we end up having throttle time equal to zero when pause is needed
|
66
|
+
# and this should not happen
|
67
|
+
throttle_timeout = filter.timeout
|
68
|
+
|
69
|
+
case filter.action
|
70
|
+
when :skip
|
71
|
+
nil
|
72
|
+
when :seek
|
73
|
+
throttle_message = filter.cursor
|
74
|
+
|
75
|
+
Karafka.monitor.instrument(
|
76
|
+
'filtering.seek',
|
77
|
+
caller: self,
|
78
|
+
message: throttle_message
|
79
|
+
) do
|
80
|
+
seek(throttle_message.offset)
|
81
|
+
end
|
82
|
+
|
83
|
+
resume
|
84
|
+
when :pause
|
85
|
+
throttle_message = filter.cursor
|
86
|
+
|
87
|
+
Karafka.monitor.instrument(
|
88
|
+
'filtering.throttled',
|
89
|
+
caller: self,
|
90
|
+
message: throttle_message,
|
91
|
+
timeout: throttle_timeout
|
92
|
+
) do
|
93
|
+
pause(throttle_message.offset, throttle_timeout, false)
|
94
|
+
end
|
95
|
+
else
|
96
|
+
raise Karafka::Errors::UnsupportedCaseError filter.action
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This Karafka component is a Pro component under a commercial license.
|
4
|
+
# This Karafka component is NOT licensed under LGPL.
|
5
|
+
#
|
6
|
+
# All of the commercial components are present in the lib/karafka/pro directory of this
|
7
|
+
# repository and their usage requires commercial license agreement.
|
8
|
+
#
|
9
|
+
# Karafka has also commercial-friendly license, commercial support and commercial components.
|
10
|
+
#
|
11
|
+
# By sending a pull request to the pro components, you are agreeing to transfer the copyright of
|
12
|
+
# your code to Maciej Mensfeld.
|
13
|
+
|
14
|
+
module Karafka
|
15
|
+
module Pro
|
16
|
+
module Processing
|
17
|
+
module Strategies
|
18
|
+
# Filtering related init strategies
|
19
|
+
module Ftr
|
20
|
+
# Filtering enabled
|
21
|
+
# VPs enabled
|
22
|
+
#
|
23
|
+
# VPs should operate without any problems with filtering because virtual partitioning
|
24
|
+
# happens on the limited set of messages and collective filtering applies the same
|
25
|
+
# way as for default cases
|
26
|
+
module Vp
|
27
|
+
# Filtering + VPs
|
28
|
+
FEATURES = %i[
|
29
|
+
filtering
|
30
|
+
virtual_partitions
|
31
|
+
].freeze
|
32
|
+
|
33
|
+
include Strategies::Vp::Default
|
34
|
+
include Strategies::Ftr::Default
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This Karafka component is a Pro component under a commercial license.
|
4
|
+
# This Karafka component is NOT licensed under LGPL.
|
5
|
+
#
|
6
|
+
# All of the commercial components are present in the lib/karafka/pro directory of this
|
7
|
+
# repository and their usage requires commercial license agreement.
|
8
|
+
#
|
9
|
+
# Karafka has also commercial-friendly license, commercial support and commercial components.
|
10
|
+
#
|
11
|
+
# By sending a pull request to the pro components, you are agreeing to transfer the copyright of
|
12
|
+
# your code to Maciej Mensfeld.
|
13
|
+
|
14
|
+
module Karafka
|
15
|
+
module Pro
|
16
|
+
module Processing
|
17
|
+
module Strategies
|
18
|
+
module Lrj
|
19
|
+
# Long-Running Job enabled
|
20
|
+
module Default
|
21
|
+
include Strategies::Default
|
22
|
+
|
23
|
+
# Pause for tops 31 years
|
24
|
+
MAX_PAUSE_TIME = 1_000_000_000_000
|
25
|
+
|
26
|
+
# Features for this strategy
|
27
|
+
FEATURES = %i[
|
28
|
+
long_running_job
|
29
|
+
].freeze
|
30
|
+
|
31
|
+
# We always need to pause prior to doing any jobs for LRJ
|
32
|
+
def handle_before_enqueue
|
33
|
+
# This ensures that when running LRJ with VP, things operate as expected run only
|
34
|
+
# once for all the virtual partitions collectively
|
35
|
+
coordinator.on_enqueued do
|
36
|
+
# Pause at the first message in a batch. That way in case of a crash, we will not
|
37
|
+
# loose any messages.
|
38
|
+
#
|
39
|
+
# For VP it applies the same way and since VP cannot be used with MOM we should not
|
40
|
+
# have any edge cases here.
|
41
|
+
pause(coordinator.seek_offset, MAX_PAUSE_TIME, false)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# LRJ standard flow after consumption
|
46
|
+
def handle_after_consume
|
47
|
+
coordinator.on_finished do |last_group_message|
|
48
|
+
if coordinator.success?
|
49
|
+
coordinator.pause_tracker.reset
|
50
|
+
|
51
|
+
return if coordinator.manual_pause?
|
52
|
+
|
53
|
+
mark_as_consumed(last_group_message) unless revoked?
|
54
|
+
seek(coordinator.seek_offset) unless revoked?
|
55
|
+
|
56
|
+
resume
|
57
|
+
else
|
58
|
+
# If processing failed, we need to pause
|
59
|
+
# For long running job this will overwrite the default never-ending pause and
|
60
|
+
# will cause the processing to keep going after the error backoff
|
61
|
+
retry_after_pause
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# We do not un-pause on revokations for LRJ
|
67
|
+
def handle_revoked
|
68
|
+
coordinator.on_revoked do
|
69
|
+
# We do not want to resume on revocation in case of a LRJ.
|
70
|
+
# For LRJ we resume after the successful processing or do a backoff pause in case
|
71
|
+
# of a failure. Double non-blocking resume could cause problems in coordination.
|
72
|
+
coordinator.revoke
|
73
|
+
end
|
74
|
+
|
75
|
+
Karafka.monitor.instrument('consumer.revoke', caller: self)
|
76
|
+
Karafka.monitor.instrument('consumer.revoked', caller: self) do
|
77
|
+
revoked
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This Karafka component is a Pro component under a commercial license.
|
4
|
+
# This Karafka component is NOT licensed under LGPL.
|
5
|
+
#
|
6
|
+
# All of the commercial components are present in the lib/karafka/pro directory of this
|
7
|
+
# repository and their usage requires commercial license agreement.
|
8
|
+
#
|
9
|
+
# Karafka has also commercial-friendly license, commercial support and commercial components.
|
10
|
+
#
|
11
|
+
# By sending a pull request to the pro components, you are agreeing to transfer the copyright of
|
12
|
+
# your code to Maciej Mensfeld.
|
13
|
+
|
14
|
+
module Karafka
|
15
|
+
module Pro
|
16
|
+
module Processing
|
17
|
+
module Strategies
|
18
|
+
module Lrj
|
19
|
+
# Filtering enabled
|
20
|
+
# Long-Running Job enabled
|
21
|
+
#
|
22
|
+
# In general aside from throttling this one will behave the same way as the Lrj
|
23
|
+
module Ftr
|
24
|
+
include Strategies::Ftr::Default
|
25
|
+
include Strategies::Lrj::Default
|
26
|
+
|
27
|
+
# Features for this strategy
|
28
|
+
FEATURES = %i[
|
29
|
+
filtering
|
30
|
+
long_running_job
|
31
|
+
].freeze
|
32
|
+
|
33
|
+
# LRJ standard flow after consumption with potential throttling on success
|
34
|
+
def handle_after_consume
|
35
|
+
coordinator.on_finished do |last_group_message|
|
36
|
+
if coordinator.success?
|
37
|
+
coordinator.pause_tracker.reset
|
38
|
+
|
39
|
+
# Manual pausing has the highest priority
|
40
|
+
return if coordinator.manual_pause?
|
41
|
+
|
42
|
+
# It's not a MoM, so for successful we need to mark as consumed
|
43
|
+
mark_as_consumed(last_group_message) unless revoked?
|
44
|
+
|
45
|
+
# If still not revoked and was throttled, we need to apply throttling logic
|
46
|
+
if coordinator.filtered? && !revoked?
|
47
|
+
handle_post_filtering
|
48
|
+
elsif !revoked?
|
49
|
+
# If not revoked and not throttled, we move to where we were suppose to and
|
50
|
+
# resume
|
51
|
+
seek(coordinator.seek_offset)
|
52
|
+
resume
|
53
|
+
else
|
54
|
+
resume
|
55
|
+
end
|
56
|
+
else
|
57
|
+
# If processing failed, we need to pause
|
58
|
+
# For long running job this will overwrite the default never-ending pause and
|
59
|
+
# will cause the processing to keep going after the error backoff
|
60
|
+
retry_after_pause
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This Karafka component is a Pro component under a commercial license.
|
4
|
+
# This Karafka component is NOT licensed under LGPL.
|
5
|
+
#
|
6
|
+
# All of the commercial components are present in the lib/karafka/pro directory of this
|
7
|
+
# repository and their usage requires commercial license agreement.
|
8
|
+
#
|
9
|
+
# Karafka has also commercial-friendly license, commercial support and commercial components.
|
10
|
+
#
|
11
|
+
# By sending a pull request to the pro components, you are agreeing to transfer the copyright of
|
12
|
+
# your code to Maciej Mensfeld.
|
13
|
+
|
14
|
+
module Karafka
|
15
|
+
module Pro
|
16
|
+
module Processing
|
17
|
+
module Strategies
|
18
|
+
module Lrj
|
19
|
+
# Long-Running Job enabled
|
20
|
+
# Filtering enabled
|
21
|
+
# Manual offset management enabled
|
22
|
+
#
|
23
|
+
# It is really similar to the Lrj::Ftr but we do not mark anything as consumed
|
24
|
+
module FtrMom
|
25
|
+
include Strategies::Lrj::Ftr
|
26
|
+
|
27
|
+
# Features for this strategy
|
28
|
+
FEATURES = %i[
|
29
|
+
filtering
|
30
|
+
long_running_job
|
31
|
+
manual_offset_management
|
32
|
+
].freeze
|
33
|
+
|
34
|
+
# LRJ standard flow after consumption with potential filtering on success
|
35
|
+
def handle_after_consume
|
36
|
+
coordinator.on_finished do |last_group_message|
|
37
|
+
if coordinator.success?
|
38
|
+
coordinator.pause_tracker.reset
|
39
|
+
|
40
|
+
# Manual pausing has the highest priority
|
41
|
+
return if coordinator.manual_pause?
|
42
|
+
|
43
|
+
# If still not revoked and was throttled, we need to apply filtering logic
|
44
|
+
if coordinator.filtered? && !revoked?
|
45
|
+
handle_post_filtering
|
46
|
+
elsif !revoked?
|
47
|
+
# If not revoked and not throttled, we move to where we were suppose to and
|
48
|
+
# resume
|
49
|
+
seek(last_group_message.offset + 1)
|
50
|
+
resume
|
51
|
+
else
|
52
|
+
resume
|
53
|
+
end
|
54
|
+
else
|
55
|
+
# If processing failed, we need to pause
|
56
|
+
# For long running job this will overwrite the default never-ending pause and
|
57
|
+
# will cause the processing to keep going after the error backoff
|
58
|
+
retry_after_pause
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -15,20 +15,22 @@ module Karafka
|
|
15
15
|
module Pro
|
16
16
|
module Processing
|
17
17
|
module Strategies
|
18
|
-
|
19
|
-
|
20
|
-
#
|
21
|
-
#
|
22
|
-
|
18
|
+
module Lrj
|
19
|
+
# Long-Running Job enabled
|
20
|
+
# Filtering enabled
|
21
|
+
# Virtual Partitions enabled
|
22
|
+
#
|
23
|
+
# Behaves same as non-VP because of the aggregated flow in the coordinator.
|
24
|
+
module FtrVp
|
25
|
+
include Strategies::Vp::Default
|
26
|
+
include Strategies::Lrj::Ftr
|
23
27
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
def collapsed?
|
31
|
-
coordinator.collapsed?
|
28
|
+
# Features for this strategy
|
29
|
+
FEATURES = %i[
|
30
|
+
filtering
|
31
|
+
long_running_job
|
32
|
+
virtual_partitions
|
33
|
+
].freeze
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This Karafka component is a Pro component under a commercial license.
|
4
|
+
# This Karafka component is NOT licensed under LGPL.
|
5
|
+
#
|
6
|
+
# All of the commercial components are present in the lib/karafka/pro directory of this
|
7
|
+
# repository and their usage requires commercial license agreement.
|
8
|
+
#
|
9
|
+
# Karafka has also commercial-friendly license, commercial support and commercial components.
|
10
|
+
#
|
11
|
+
# By sending a pull request to the pro components, you are agreeing to transfer the copyright of
|
12
|
+
# your code to Maciej Mensfeld.
|
13
|
+
|
14
|
+
module Karafka
|
15
|
+
module Pro
|
16
|
+
module Processing
|
17
|
+
module Strategies
|
18
|
+
# Namespace for all the LRJ starting strategies
|
19
|
+
module Lrj
|
20
|
+
# Long-Running Job enabled
|
21
|
+
# Manual offset management enabled
|
22
|
+
module Mom
|
23
|
+
include Strategies::Default
|
24
|
+
|
25
|
+
# Features for this strategy
|
26
|
+
FEATURES = %i[
|
27
|
+
long_running_job
|
28
|
+
manual_offset_management
|
29
|
+
].freeze
|
30
|
+
|
31
|
+
# We always need to pause prior to doing any jobs for LRJ
|
32
|
+
def handle_before_enqueue
|
33
|
+
# This ensures that when running LRJ with VP, things operate as expected run only
|
34
|
+
# once for all the virtual partitions collectively
|
35
|
+
coordinator.on_enqueued do
|
36
|
+
# Pause at the first message in a batch. That way in case of a crash, we will not
|
37
|
+
# loose any messages.
|
38
|
+
#
|
39
|
+
# For VP it applies the same way and since VP cannot be used with MOM we should not
|
40
|
+
# have any edge cases here.
|
41
|
+
pause(coordinator.seek_offset, Strategies::Lrj::Default::MAX_PAUSE_TIME, false)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# No offset management, aside from that typical LRJ
|
46
|
+
def handle_after_consume
|
47
|
+
coordinator.on_finished do |last_group_message|
|
48
|
+
if coordinator.success?
|
49
|
+
coordinator.pause_tracker.reset
|
50
|
+
|
51
|
+
return if coordinator.manual_pause?
|
52
|
+
|
53
|
+
seek(last_group_message.offset + 1) unless revoked?
|
54
|
+
|
55
|
+
resume
|
56
|
+
else
|
57
|
+
retry_after_pause
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# We do not un-pause on revokations for LRJ
|
63
|
+
def handle_revoked
|
64
|
+
coordinator.on_revoked do
|
65
|
+
coordinator.revoke
|
66
|
+
end
|
67
|
+
|
68
|
+
Karafka.monitor.instrument('consumer.revoke', caller: self)
|
69
|
+
Karafka.monitor.instrument('consumer.revoked', caller: self) do
|
70
|
+
revoked
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -15,19 +15,20 @@ module Karafka
|
|
15
15
|
module Pro
|
16
16
|
module Processing
|
17
17
|
module Strategies
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
module Lrj
|
19
|
+
# Long-Running Job enabled
|
20
|
+
# Virtual Partitions enabled
|
21
|
+
module Vp
|
22
|
+
# Same flow as the standard Lrj
|
23
|
+
include Strategies::Vp::Default
|
24
|
+
include Strategies::Lrj::Default
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
# Features for this strategy
|
27
|
+
FEATURES = %i[
|
28
|
+
long_running_job
|
29
|
+
virtual_partitions
|
30
|
+
].freeze
|
31
|
+
end
|
31
32
|
end
|
32
33
|
end
|
33
34
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This Karafka component is a Pro component under a commercial license.
|
4
|
+
# This Karafka component is NOT licensed under LGPL.
|
5
|
+
#
|
6
|
+
# All of the commercial components are present in the lib/karafka/pro directory of this
|
7
|
+
# repository and their usage requires commercial license agreement.
|
8
|
+
#
|
9
|
+
# Karafka has also commercial-friendly license, commercial support and commercial components.
|
10
|
+
#
|
11
|
+
# By sending a pull request to the pro components, you are agreeing to transfer the copyright of
|
12
|
+
# your code to Maciej Mensfeld.
|
13
|
+
|
14
|
+
module Karafka
|
15
|
+
module Pro
|
16
|
+
module Processing
|
17
|
+
module Strategies
|
18
|
+
# Namespace for Mom starting strategies
|
19
|
+
module Mom
|
20
|
+
# Manual offset management enabled
|
21
|
+
module Default
|
22
|
+
include Strategies::Default
|
23
|
+
|
24
|
+
# Features for this strategy
|
25
|
+
FEATURES = %i[
|
26
|
+
manual_offset_management
|
27
|
+
].freeze
|
28
|
+
|
29
|
+
# When mom is enabled, we do not mark messages as consumed after processing
|
30
|
+
def handle_after_consume
|
31
|
+
coordinator.on_finished do
|
32
|
+
return if revoked?
|
33
|
+
|
34
|
+
if coordinator.success?
|
35
|
+
coordinator.pause_tracker.reset
|
36
|
+
else
|
37
|
+
retry_after_pause
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|