karafka 2.0.14 → 2.0.16
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/.rspec +2 -0
- data/CHANGELOG.md +84 -0
- data/Gemfile.lock +14 -14
- data/LICENSE +1 -1
- data/README.md +2 -1
- data/bin/integrations +3 -2
- data/bin/rspecs +4 -0
- data/config/errors.yml +10 -4
- data/lib/active_job/karafka.rb +0 -6
- data/lib/karafka/active_job/consumer.rb +1 -0
- data/lib/karafka/admin.rb +6 -3
- data/lib/karafka/base_consumer.rb +31 -21
- data/lib/karafka/connection/client.rb +2 -4
- data/lib/karafka/connection/listener.rb +6 -4
- data/lib/karafka/contracts/consumer_group.rb +0 -14
- data/lib/karafka/contracts/{consumer_group_topic.rb → topic.rb} +2 -3
- data/lib/karafka/errors.rb +6 -4
- data/lib/karafka/instrumentation/logger_listener.rb +25 -11
- data/lib/karafka/instrumentation/notifications.rb +2 -0
- data/lib/karafka/instrumentation/vendors/datadog/dashboard.json +1 -1
- data/lib/karafka/instrumentation/vendors/datadog/listener.rb +59 -32
- data/lib/karafka/instrumentation/vendors/datadog/logger_listener.rb +153 -0
- data/lib/karafka/pro/active_job/consumer.rb +3 -1
- data/lib/karafka/pro/active_job/dispatcher.rb +3 -1
- data/lib/karafka/pro/active_job/job_options_contract.rb +3 -1
- data/lib/karafka/pro/base_consumer.rb +3 -85
- data/lib/karafka/pro/loader.rb +31 -24
- data/lib/karafka/pro/performance_tracker.rb +3 -1
- data/lib/karafka/pro/processing/coordinator.rb +16 -1
- data/lib/karafka/pro/processing/jobs/consume_non_blocking.rb +3 -1
- data/lib/karafka/pro/processing/jobs_builder.rb +3 -1
- data/lib/karafka/pro/processing/partitioner.rb +14 -17
- data/lib/karafka/pro/processing/scheduler.rb +3 -1
- data/lib/karafka/pro/processing/strategies/aj_dlq_lrj_mom.rb +40 -0
- data/lib/karafka/pro/processing/strategies/aj_dlq_mom.rb +62 -0
- data/lib/karafka/pro/processing/strategies/aj_lrj_mom.rb +35 -0
- data/lib/karafka/pro/processing/strategies/aj_lrj_mom_vp.rb +69 -0
- data/lib/karafka/pro/processing/strategies/aj_mom.rb +33 -0
- data/lib/karafka/pro/processing/strategies/aj_mom_vp.rb +58 -0
- data/lib/karafka/pro/processing/strategies/base.rb +26 -0
- data/lib/karafka/pro/processing/strategies/default.rb +69 -0
- data/lib/karafka/pro/processing/strategies/dlq.rb +88 -0
- data/lib/karafka/pro/processing/strategies/dlq_lrj.rb +64 -0
- data/lib/karafka/pro/processing/strategies/dlq_lrj_mom.rb +60 -0
- data/lib/karafka/pro/processing/strategies/dlq_mom.rb +58 -0
- data/lib/karafka/pro/processing/strategies/lrj.rb +76 -0
- data/lib/karafka/pro/processing/strategies/lrj_mom.rb +68 -0
- data/lib/karafka/pro/processing/strategies/lrj_vp.rb +33 -0
- data/lib/karafka/pro/processing/strategies/mom.rb +43 -0
- data/lib/karafka/pro/processing/strategies/vp.rb +32 -0
- data/lib/karafka/pro/processing/strategy_selector.rb +58 -0
- data/lib/karafka/pro/{contracts → routing/features}/base.rb +8 -5
- data/lib/karafka/pro/routing/features/dead_letter_queue/contract.rb +49 -0
- data/lib/karafka/pro/routing/{builder_extensions.rb → features/dead_letter_queue.rb} +9 -12
- data/lib/karafka/pro/routing/features/long_running_job/config.rb +28 -0
- data/lib/karafka/pro/routing/features/long_running_job/contract.rb +37 -0
- data/lib/karafka/pro/routing/features/long_running_job/topic.rb +42 -0
- data/lib/karafka/pro/routing/features/long_running_job.rb +28 -0
- data/lib/karafka/pro/routing/features/virtual_partitions/config.rb +30 -0
- data/lib/karafka/pro/routing/features/virtual_partitions/contract.rb +69 -0
- data/lib/karafka/pro/routing/features/virtual_partitions/topic.rb +56 -0
- data/lib/karafka/pro/routing/features/virtual_partitions.rb +27 -0
- data/lib/karafka/processing/coordinator.rb +1 -1
- data/lib/karafka/processing/executor.rb +6 -0
- data/lib/karafka/processing/strategies/aj_dlq_mom.rb +44 -0
- data/lib/karafka/processing/strategies/aj_mom.rb +21 -0
- data/lib/karafka/processing/strategies/base.rb +37 -0
- data/lib/karafka/processing/strategies/default.rb +52 -0
- data/lib/karafka/processing/strategies/dlq.rb +77 -0
- data/lib/karafka/processing/strategies/dlq_mom.rb +42 -0
- data/lib/karafka/processing/strategies/mom.rb +29 -0
- data/lib/karafka/processing/strategy_selector.rb +30 -0
- data/lib/karafka/railtie.rb +9 -8
- data/lib/karafka/routing/builder.rb +6 -0
- data/lib/karafka/routing/features/active_job/builder.rb +33 -0
- data/lib/karafka/routing/features/active_job/config.rb +15 -0
- data/lib/karafka/routing/features/active_job/contract.rb +41 -0
- data/lib/karafka/routing/features/active_job/topic.rb +33 -0
- data/lib/karafka/routing/features/active_job.rb +13 -0
- data/lib/karafka/routing/features/base/expander.rb +53 -0
- data/lib/karafka/routing/features/base.rb +34 -0
- data/lib/karafka/routing/features/dead_letter_queue/config.rb +19 -0
- data/lib/karafka/routing/features/dead_letter_queue/contract.rb +40 -0
- data/lib/karafka/routing/features/dead_letter_queue/topic.rb +40 -0
- data/lib/karafka/routing/features/dead_letter_queue.rb +16 -0
- data/lib/karafka/routing/features/manual_offset_management/config.rb +15 -0
- data/lib/karafka/routing/features/manual_offset_management/contract.rb +24 -0
- data/lib/karafka/routing/features/manual_offset_management/topic.rb +35 -0
- data/lib/karafka/routing/features/manual_offset_management.rb +18 -0
- data/lib/karafka/routing/topic.rb +2 -10
- data/lib/karafka/server.rb +4 -2
- data/lib/karafka/setup/attributes_map.rb +5 -0
- data/lib/karafka/setup/config.rb +4 -4
- data/lib/karafka/time_trackers/pause.rb +21 -12
- data/lib/karafka/version.rb +1 -1
- data/lib/karafka.rb +7 -11
- data.tar.gz.sig +0 -0
- metadata +57 -9
- metadata.gz.sig +0 -0
- data/lib/karafka/active_job/routing/extensions.rb +0 -33
- data/lib/karafka/pro/contracts/consumer_group.rb +0 -34
- data/lib/karafka/pro/contracts/consumer_group_topic.rb +0 -69
- data/lib/karafka/pro/routing/topic_extensions.rb +0 -74
data/lib/karafka/pro/loader.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# This Karafka component is a Pro component.
|
3
|
+
# This Karafka component is a Pro component under a commercial license.
|
4
|
+
# This Karafka component is NOT licensed under LGPL.
|
5
|
+
#
|
4
6
|
# All of the commercial components are present in the lib/karafka/pro directory of this
|
5
7
|
# repository and their usage requires commercial license agreement.
|
6
8
|
#
|
@@ -13,37 +15,41 @@ module Karafka
|
|
13
15
|
module Pro
|
14
16
|
# Loader requires and loads all the pro components only when they are needed
|
15
17
|
class Loader
|
16
|
-
#
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
processing/scheduler
|
21
|
-
processing/jobs/consume_non_blocking
|
22
|
-
processing/jobs_builder
|
23
|
-
processing/coordinator
|
24
|
-
processing/partitioner
|
25
|
-
contracts/base
|
26
|
-
contracts/consumer_group
|
27
|
-
contracts/consumer_group_topic
|
28
|
-
routing/topic_extensions
|
29
|
-
routing/builder_extensions
|
30
|
-
active_job/consumer
|
18
|
+
# There seems to be a conflict in between using two Zeitwerk instances and it makes lookups
|
19
|
+
# for nested namespaces instead of creating them.
|
20
|
+
# We require those not to deal with this and then all works as expected
|
21
|
+
FORCE_LOADED = %w[
|
31
22
|
active_job/dispatcher
|
32
|
-
|
23
|
+
processing/jobs/consume_non_blocking
|
24
|
+
processing/strategies/base
|
25
|
+
routing/features/base
|
33
26
|
].freeze
|
34
27
|
|
35
|
-
|
28
|
+
# Zeitwerk pro loader
|
29
|
+
# We need to have one per process, that's why it's set as a constant
|
30
|
+
PRO_LOADER = Zeitwerk::Loader.new
|
31
|
+
|
32
|
+
private_constant :PRO_LOADER
|
36
33
|
|
37
34
|
class << self
|
35
|
+
# Requires all the components without using them anywhere
|
36
|
+
def require_all
|
37
|
+
FORCE_LOADED.each { |file| require_relative(file) }
|
38
|
+
|
39
|
+
PRO_LOADER.push_dir(Karafka.core_root.join('pro'), namespace: Karafka::Pro)
|
40
|
+
PRO_LOADER.setup
|
41
|
+
PRO_LOADER.eager_load
|
42
|
+
end
|
43
|
+
|
38
44
|
# Loads all the pro components and configures them wherever it is expected
|
39
45
|
# @param config [Karafka::Core::Configurable::Node] app config that we can alter with pro
|
40
46
|
# components
|
41
47
|
def setup(config)
|
42
|
-
|
48
|
+
require_all
|
43
49
|
|
44
50
|
reconfigure(config)
|
45
51
|
|
46
|
-
|
52
|
+
load_topic_features
|
47
53
|
end
|
48
54
|
|
49
55
|
private
|
@@ -57,6 +63,7 @@ module Karafka
|
|
57
63
|
icfg.processing.partitioner_class = Processing::Partitioner
|
58
64
|
icfg.processing.scheduler = Processing::Scheduler.new
|
59
65
|
icfg.processing.jobs_builder = Processing::JobsBuilder.new
|
66
|
+
icfg.processing.strategy_selector = Processing::StrategySelector.new
|
60
67
|
|
61
68
|
icfg.active_job.consumer_class = ActiveJob::Consumer
|
62
69
|
icfg.active_job.dispatcher = ActiveJob::Dispatcher.new
|
@@ -65,10 +72,10 @@ module Karafka
|
|
65
72
|
config.monitor.subscribe(PerformanceTracker.instance)
|
66
73
|
end
|
67
74
|
|
68
|
-
# Loads
|
69
|
-
|
70
|
-
|
71
|
-
::Karafka::Routing::
|
75
|
+
# Loads the Pro features of Karafka
|
76
|
+
# @note Object space lookup is not the fastest but we do it once during boot, so it's ok
|
77
|
+
def load_topic_features
|
78
|
+
::Karafka::Pro::Routing::Features::Base.load_all
|
72
79
|
end
|
73
80
|
end
|
74
81
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# This Karafka component is a Pro component.
|
3
|
+
# This Karafka component is a Pro component under a commercial license.
|
4
|
+
# This Karafka component is NOT licensed under LGPL.
|
5
|
+
#
|
4
6
|
# All of the commercial components are present in the lib/karafka/pro directory of this
|
5
7
|
# repository and their usage requires commercial license agreement.
|
6
8
|
#
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# This Karafka component is a Pro component.
|
3
|
+
# This Karafka component is a Pro component under a commercial license.
|
4
|
+
# This Karafka component is NOT licensed under LGPL.
|
5
|
+
#
|
4
6
|
# All of the commercial components are present in the lib/karafka/pro directory of this
|
5
7
|
# repository and their usage requires commercial license agreement.
|
6
8
|
#
|
@@ -21,6 +23,7 @@ module Karafka
|
|
21
23
|
@on_enqueued_invoked = false
|
22
24
|
@on_started_invoked = false
|
23
25
|
@on_finished_invoked = false
|
26
|
+
@on_revoked_invoked = false
|
24
27
|
@flow_lock = Mutex.new
|
25
28
|
end
|
26
29
|
|
@@ -79,6 +82,18 @@ module Karafka
|
|
79
82
|
yield(@last_message)
|
80
83
|
end
|
81
84
|
end
|
85
|
+
|
86
|
+
# Runs once when a partition is revoked
|
87
|
+
def on_revoked
|
88
|
+
@flow_lock.synchronize do
|
89
|
+
return unless finished?
|
90
|
+
return if @on_revoked_invoked
|
91
|
+
|
92
|
+
@on_revoked_invoked = true
|
93
|
+
|
94
|
+
yield(@last_message)
|
95
|
+
end
|
96
|
+
end
|
82
97
|
end
|
83
98
|
end
|
84
99
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# This Karafka component is a Pro component.
|
3
|
+
# This Karafka component is a Pro component under a commercial license.
|
4
|
+
# This Karafka component is NOT licensed under LGPL.
|
5
|
+
#
|
4
6
|
# All of the commercial components are present in the lib/karafka/pro directory of this
|
5
7
|
# repository and their usage requires commercial license agreement.
|
6
8
|
#
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# This Karafka component is a Pro component.
|
3
|
+
# This Karafka component is a Pro component under a commercial license.
|
4
|
+
# This Karafka component is NOT licensed under LGPL.
|
5
|
+
#
|
4
6
|
# All of the commercial components are present in the lib/karafka/pro directory of this
|
5
7
|
# repository and their usage requires commercial license agreement.
|
6
8
|
#
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# This Karafka component is a Pro component.
|
3
|
+
# This Karafka component is a Pro component under a commercial license.
|
4
|
+
# This Karafka component is NOT licensed under LGPL.
|
5
|
+
#
|
4
6
|
# All of the commercial components are present in the lib/karafka/pro directory of this
|
5
7
|
# repository and their usage requires commercial license agreement.
|
6
8
|
#
|
@@ -25,28 +27,23 @@ module Karafka
|
|
25
27
|
# process the data. With one thread it is not worth partitioning the work as the work
|
26
28
|
# itself will be assigned to one thread (pointless work)
|
27
29
|
if ktopic.virtual_partitions? && ktopic.virtual_partitions.max_partitions > 1
|
28
|
-
# We need to reduce it to
|
30
|
+
# We need to reduce it to the max concurrency, so the group_id is not a direct effect
|
29
31
|
# of the end user action. Otherwise the persistence layer for consumers would cache
|
30
32
|
# it forever and it would cause memory leaks
|
31
|
-
groupings = messages
|
32
|
-
.group_by { |msg| ktopic.virtual_partitions.partitioner.call(msg) }
|
33
|
-
.values
|
34
|
-
|
35
|
-
# Reduce the number of virtual partitions to a size that matches the max_partitions
|
36
|
-
# As mentioned above we cannot use the partitioning keys directly as it could cause
|
37
|
-
# memory leaks
|
38
33
|
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
|
43
|
-
|
34
|
+
# This also needs to be consistent because the aggregation here needs to warrant, that
|
35
|
+
# the same partitioned message will always be assigned to the same virtual partition.
|
36
|
+
# Otherwise in case of a window aggregation with VP spanning across several polls, the
|
37
|
+
# data could not be complete.
|
38
|
+
groupings = messages.group_by do |msg|
|
39
|
+
key = ktopic.virtual_partitions.partitioner.call(msg).to_s.sum
|
44
40
|
|
45
|
-
|
46
|
-
groupings << (groupings.pop + groupings.pop).sort_by!(&:offset)
|
41
|
+
key % ktopic.virtual_partitions.max_partitions
|
47
42
|
end
|
48
43
|
|
49
|
-
groupings.
|
44
|
+
groupings.each do |key, messages_group|
|
45
|
+
yield(key, messages_group)
|
46
|
+
end
|
50
47
|
else
|
51
48
|
# When no virtual partitioner, works as regular one
|
52
49
|
yield(0, messages)
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# This Karafka component is a Pro component.
|
3
|
+
# This Karafka component is a Pro component under a commercial license.
|
4
|
+
# This Karafka component is NOT licensed under LGPL.
|
5
|
+
#
|
4
6
|
# All of the commercial components are present in the lib/karafka/pro directory of this
|
5
7
|
# repository and their usage requires commercial license agreement.
|
6
8
|
#
|
@@ -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
|
+
# ActiveJob enabled
|
19
|
+
# DLQ enabled
|
20
|
+
# Long-Running Job enabled
|
21
|
+
# Manual offset management enabled
|
22
|
+
#
|
23
|
+
# This case is a bit of special. Please see the `AjDlqMom` for explanation on how the
|
24
|
+
# offset management works in this case.
|
25
|
+
module AjDlqLrjMom
|
26
|
+
include AjLrjMom
|
27
|
+
include AjDlqMom
|
28
|
+
|
29
|
+
# Features for this strategy
|
30
|
+
FEATURES = %i[
|
31
|
+
active_job
|
32
|
+
long_running_job
|
33
|
+
manual_offset_management
|
34
|
+
dead_letter_queue
|
35
|
+
].freeze
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,62 @@
|
|
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
|
+
# ActiveJob enabled
|
19
|
+
# DLQ enabled
|
20
|
+
# Manual offset management enabled
|
21
|
+
#
|
22
|
+
# AJ has manual offset management on by default and the offset management is delegated to
|
23
|
+
# the AJ consumer. This means, we cannot mark as consumed always. We can only mark as
|
24
|
+
# consumed when we skip given job upon errors. In all the other scenarions marking as
|
25
|
+
# consumed needs to happen in the AJ consumer on a per job basis.
|
26
|
+
module AjDlqMom
|
27
|
+
include DlqMom
|
28
|
+
|
29
|
+
# Features for this strategy
|
30
|
+
FEATURES = %i[
|
31
|
+
active_job
|
32
|
+
dead_letter_queue
|
33
|
+
manual_offset_management
|
34
|
+
].freeze
|
35
|
+
|
36
|
+
# How should we post-finalize consumption.
|
37
|
+
def handle_after_consume
|
38
|
+
coordinator.on_finished do
|
39
|
+
return if revoked?
|
40
|
+
|
41
|
+
if coordinator.success?
|
42
|
+
# Do NOT commit offsets, they are comitted after each job in the AJ consumer.
|
43
|
+
coordinator.pause_tracker.reset
|
44
|
+
elsif coordinator.pause_tracker.attempt <= topic.dead_letter_queue.max_retries
|
45
|
+
pause(coordinator.seek_offset)
|
46
|
+
else
|
47
|
+
coordinator.pause_tracker.reset
|
48
|
+
skippable_message = find_skippable_message
|
49
|
+
dispatch_to_dlq(skippable_message)
|
50
|
+
# We can commit the offset here because we know that we skip it "forever" and
|
51
|
+
# since AJ consumer commits the offset after each job, we also know that the
|
52
|
+
# previous job was successful
|
53
|
+
mark_as_consumed(skippable_message)
|
54
|
+
pause(coordinator.seek_offset)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,35 @@
|
|
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
|
+
# ActiveJob enabled
|
19
|
+
# Long-Running Job enabled
|
20
|
+
# Manual offset management enabled
|
21
|
+
module AjLrjMom
|
22
|
+
# Same behaviour as LrjMom
|
23
|
+
include LrjMom
|
24
|
+
|
25
|
+
# Features for this strategy
|
26
|
+
FEATURES = %i[
|
27
|
+
active_job
|
28
|
+
long_running_job
|
29
|
+
manual_offset_management
|
30
|
+
].freeze
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
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
|
+
# ActiveJob enabled
|
19
|
+
# Long-Running Job enabled
|
20
|
+
# Manual offset management enabled
|
21
|
+
# Virtual Partitions enabled
|
22
|
+
module AjLrjMomVp
|
23
|
+
include Default
|
24
|
+
|
25
|
+
# Features for this strategy
|
26
|
+
FEATURES = %i[
|
27
|
+
active_job
|
28
|
+
long_running_job
|
29
|
+
manual_offset_management
|
30
|
+
virtual_partitions
|
31
|
+
].freeze
|
32
|
+
|
33
|
+
# No actions needed for the standard flow here
|
34
|
+
def handle_before_enqueue
|
35
|
+
coordinator.on_enqueued do
|
36
|
+
pause(coordinator.seek_offset, Lrj::MAX_PAUSE_TIME)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Standard flow without any features
|
41
|
+
def handle_after_consume
|
42
|
+
coordinator.on_finished do |last_group_message|
|
43
|
+
if coordinator.success?
|
44
|
+
coordinator.pause_tracker.reset
|
45
|
+
|
46
|
+
mark_as_consumed(last_group_message) unless revoked? || Karafka::App.stopping?
|
47
|
+
seek(coordinator.seek_offset) unless revoked?
|
48
|
+
|
49
|
+
resume
|
50
|
+
else
|
51
|
+
# If processing failed, we need to pause
|
52
|
+
# For long running job this will overwrite the default never-ending pause and will
|
53
|
+
# cause the processing to keep going after the error backoff
|
54
|
+
pause(coordinator.seek_offset)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# LRJ cannot resume here. Only in handling the after consumption
|
60
|
+
def handle_revoked
|
61
|
+
coordinator.on_revoked do
|
62
|
+
coordinator.revoke
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,33 @@
|
|
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
|
+
# ActiveJob enabled
|
19
|
+
# Manual Offset management enabled
|
20
|
+
module AjMom
|
21
|
+
# Standard ActiveJob strategy is the same one we use for Mom
|
22
|
+
include Mom
|
23
|
+
|
24
|
+
# Features for this strategy
|
25
|
+
FEATURES = %i[
|
26
|
+
active_job
|
27
|
+
manual_offset_management
|
28
|
+
].freeze
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,58 @@
|
|
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
|
+
# ActiveJob enabled
|
19
|
+
# Manual offset management enabled
|
20
|
+
# Virtual Partitions enabled
|
21
|
+
module AjMomVp
|
22
|
+
include Default
|
23
|
+
|
24
|
+
# Features for this strategy
|
25
|
+
FEATURES = %i[
|
26
|
+
active_job
|
27
|
+
manual_offset_management
|
28
|
+
virtual_partitions
|
29
|
+
].freeze
|
30
|
+
|
31
|
+
# Standard flow without any features
|
32
|
+
def handle_after_consume
|
33
|
+
coordinator.on_finished do |last_group_message|
|
34
|
+
if coordinator.success?
|
35
|
+
coordinator.pause_tracker.reset
|
36
|
+
|
37
|
+
# When this is an ActiveJob running via Pro with virtual partitions, we cannot mark
|
38
|
+
# intermediate jobs as processed not to mess up with the ordering.
|
39
|
+
# Only when all the jobs are processed and we did not loose the partition
|
40
|
+
# assignment and we are not stopping (Pro ActiveJob has an early break) we can
|
41
|
+
# commit offsets on this as only then we can be sure, that all the jobs were
|
42
|
+
# processed.
|
43
|
+
# For a non virtual partitions case, the flow is regular and state is marked after
|
44
|
+
# each successfully processed job
|
45
|
+
return if revoked?
|
46
|
+
return if Karafka::App.stopping?
|
47
|
+
|
48
|
+
mark_as_consumed(last_group_message)
|
49
|
+
else
|
50
|
+
pause(coordinator.seek_offset)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,26 @@
|
|
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
|
+
# Pro processing strategies namespace
|
18
|
+
module Strategies
|
19
|
+
# Base strategy for Pro
|
20
|
+
module Base
|
21
|
+
include ::Karafka::Processing::Strategies::Base
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
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
|
+
# No features enabled.
|
19
|
+
# No manual offset management
|
20
|
+
# No long running jobs
|
21
|
+
# No virtual partitions
|
22
|
+
# Nothing. Just standard, automatic flow
|
23
|
+
module Default
|
24
|
+
include Base
|
25
|
+
|
26
|
+
# Apply strategy for a non-feature based flow
|
27
|
+
FEATURES = %i[].freeze
|
28
|
+
|
29
|
+
# No actions needed for the standard flow here
|
30
|
+
def handle_before_enqueue
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
|
34
|
+
# Increment number of attempts per one "full" job. For all VP on a single topic partition
|
35
|
+
# this also should run once.
|
36
|
+
def handle_before_consume
|
37
|
+
coordinator.on_started do
|
38
|
+
coordinator.pause_tracker.increment
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Standard flow without any features
|
43
|
+
def handle_after_consume
|
44
|
+
coordinator.on_finished do |last_group_message|
|
45
|
+
return if revoked?
|
46
|
+
|
47
|
+
if coordinator.success?
|
48
|
+
coordinator.pause_tracker.reset
|
49
|
+
|
50
|
+
mark_as_consumed(last_group_message)
|
51
|
+
else
|
52
|
+
pause(coordinator.seek_offset)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Standard
|
58
|
+
def handle_revoked
|
59
|
+
coordinator.on_revoked do
|
60
|
+
resume
|
61
|
+
|
62
|
+
coordinator.revoke
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|