karafka 2.0.15 → 2.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/.github/workflows/ci.yml +1 -1
- data/.rspec +2 -0
- data/CHANGELOG.md +78 -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 +2 -2
- data/lib/karafka/base_consumer.rb +31 -21
- 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 +37 -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 +3 -1
- 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
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
# Strategy for supporting DLQ with Mom and LRJ enabled
|
|
19
|
+
module DlqLrjMom
|
|
20
|
+
# This strategy needs to pause and revoke same way as DlqLrj but without the offset
|
|
21
|
+
# management
|
|
22
|
+
include DlqLrj
|
|
23
|
+
|
|
24
|
+
# Features for this strategy
|
|
25
|
+
FEATURES = %i[
|
|
26
|
+
dead_letter_queue
|
|
27
|
+
long_running_job
|
|
28
|
+
manual_offset_management
|
|
29
|
+
].freeze
|
|
30
|
+
|
|
31
|
+
# LRJ standard flow after consumption with DLQ dispatch and no offset management
|
|
32
|
+
def handle_after_consume
|
|
33
|
+
coordinator.on_finished do
|
|
34
|
+
if coordinator.success?
|
|
35
|
+
coordinator.pause_tracker.reset
|
|
36
|
+
|
|
37
|
+
seek(coordinator.seek_offset) unless revoked?
|
|
38
|
+
|
|
39
|
+
resume
|
|
40
|
+
elsif coordinator.pause_tracker.attempt <= topic.dead_letter_queue.max_retries
|
|
41
|
+
pause(coordinator.seek_offset)
|
|
42
|
+
else
|
|
43
|
+
coordinator.pause_tracker.reset
|
|
44
|
+
|
|
45
|
+
skippable_message = find_skippable_message
|
|
46
|
+
|
|
47
|
+
unless revoked?
|
|
48
|
+
dispatch_to_dlq(skippable_message)
|
|
49
|
+
seek(coordinator.seek_offset)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
resume
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
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
|
+
# Strategy for supporting DLQ with Mom enabled
|
|
19
|
+
module DlqMom
|
|
20
|
+
# The broken message lookup is the same in this scenario
|
|
21
|
+
include Dlq
|
|
22
|
+
|
|
23
|
+
# Features for this strategy
|
|
24
|
+
FEATURES = %i[
|
|
25
|
+
dead_letter_queue
|
|
26
|
+
manual_offset_management
|
|
27
|
+
].freeze
|
|
28
|
+
|
|
29
|
+
# When manual offset management is on, we do not mark anything as consumed automatically
|
|
30
|
+
# and we rely on the user to figure things out
|
|
31
|
+
def handle_after_consume
|
|
32
|
+
coordinator.on_finished do
|
|
33
|
+
return if revoked?
|
|
34
|
+
|
|
35
|
+
if coordinator.success?
|
|
36
|
+
coordinator.pause_tracker.reset
|
|
37
|
+
elsif coordinator.pause_tracker.attempt <= topic.dead_letter_queue.max_retries
|
|
38
|
+
pause(coordinator.seek_offset)
|
|
39
|
+
# If we've reached number of retries that we could, we need to skip the first message
|
|
40
|
+
# that was not marked as consumed, pause and continue, while also moving this message
|
|
41
|
+
# to the dead topic.
|
|
42
|
+
#
|
|
43
|
+
# For a Mom setup, this means, that user has to manage the checkpointing by himself.
|
|
44
|
+
# If no checkpointing is ever done, we end up with an endless loop.
|
|
45
|
+
else
|
|
46
|
+
# We reset the pause to indicate we will now consider it as "ok".
|
|
47
|
+
coordinator.pause_tracker.reset
|
|
48
|
+
skippable_message = find_skippable_message
|
|
49
|
+
dispatch_to_dlq(skippable_message)
|
|
50
|
+
pause(coordinator.seek_offset)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
# Long-Running Job enabled
|
|
19
|
+
module Lrj
|
|
20
|
+
include Default
|
|
21
|
+
|
|
22
|
+
# Pause for tops 31 years
|
|
23
|
+
MAX_PAUSE_TIME = 1_000_000_000_000
|
|
24
|
+
|
|
25
|
+
# Features for this strategy
|
|
26
|
+
FEATURES = %i[
|
|
27
|
+
long_running_job
|
|
28
|
+
].freeze
|
|
29
|
+
|
|
30
|
+
# We always need to pause prior to doing any jobs for LRJ
|
|
31
|
+
def handle_before_enqueue
|
|
32
|
+
# This ensures that when running LRJ with VP, things operate as expected run only once
|
|
33
|
+
# for all the virtual partitions collectively
|
|
34
|
+
coordinator.on_enqueued do
|
|
35
|
+
# Pause at the first message in a batch. That way in case of a crash, we will not
|
|
36
|
+
# loose any messages.
|
|
37
|
+
#
|
|
38
|
+
# For VP it applies the same way and since VP cannot be used with MOM we should not
|
|
39
|
+
# have any edge cases here.
|
|
40
|
+
pause(coordinator.seek_offset, MAX_PAUSE_TIME)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# LRJ standard flow after consumption
|
|
45
|
+
def handle_after_consume
|
|
46
|
+
coordinator.on_finished do |last_group_message|
|
|
47
|
+
if coordinator.success?
|
|
48
|
+
coordinator.pause_tracker.reset
|
|
49
|
+
|
|
50
|
+
mark_as_consumed(last_group_message) unless revoked?
|
|
51
|
+
seek(coordinator.seek_offset) unless revoked?
|
|
52
|
+
|
|
53
|
+
resume
|
|
54
|
+
else
|
|
55
|
+
# If processing failed, we need to pause
|
|
56
|
+
# For long running job this will overwrite the default never-ending pause and will
|
|
57
|
+
# cause the processing to keep going after the error backoff
|
|
58
|
+
pause(coordinator.seek_offset)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# We do not un-pause on revokations for LRJ
|
|
64
|
+
def handle_revoked
|
|
65
|
+
coordinator.on_revoked do
|
|
66
|
+
# We do not want to resume on revocation in case of a LRJ.
|
|
67
|
+
# For LRJ we resume after the successful processing or do a backoff pause in case of
|
|
68
|
+
# a failure. Double non-blocking resume could cause problems in coordination.
|
|
69
|
+
coordinator.revoke
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
# Long-Running Job enabled
|
|
19
|
+
# Manual offset management enabled
|
|
20
|
+
module LrjMom
|
|
21
|
+
include Default
|
|
22
|
+
|
|
23
|
+
# Features for this strategy
|
|
24
|
+
FEATURES = %i[
|
|
25
|
+
long_running_job
|
|
26
|
+
manual_offset_management
|
|
27
|
+
].freeze
|
|
28
|
+
|
|
29
|
+
# We always need to pause prior to doing any jobs for LRJ
|
|
30
|
+
def handle_before_enqueue
|
|
31
|
+
# This ensures that when running LRJ with VP, things operate as expected run only once
|
|
32
|
+
# for all the virtual partitions collectively
|
|
33
|
+
coordinator.on_enqueued do
|
|
34
|
+
# Pause at the first message in a batch. That way in case of a crash, we will not
|
|
35
|
+
# loose any messages.
|
|
36
|
+
#
|
|
37
|
+
# For VP it applies the same way and since VP cannot be used with MOM we should not
|
|
38
|
+
# have any edge cases here.
|
|
39
|
+
pause(coordinator.seek_offset, Lrj::MAX_PAUSE_TIME)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# No offset management, aside from that typical LRJ
|
|
44
|
+
def handle_after_consume
|
|
45
|
+
coordinator.on_finished do
|
|
46
|
+
if coordinator.success?
|
|
47
|
+
coordinator.pause_tracker.reset
|
|
48
|
+
|
|
49
|
+
seek(coordinator.seek_offset) unless revoked?
|
|
50
|
+
|
|
51
|
+
resume
|
|
52
|
+
else
|
|
53
|
+
pause(coordinator.seek_offset)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# We do not un-pause on revokations for LRJ
|
|
59
|
+
def handle_revoked
|
|
60
|
+
coordinator.on_revoked do
|
|
61
|
+
coordinator.revoke
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
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
|
+
# Long-Running Job enabled
|
|
19
|
+
# Virtual Partitions enabled
|
|
20
|
+
module LrjVp
|
|
21
|
+
# Same flow as the standard Lrj
|
|
22
|
+
include Lrj
|
|
23
|
+
|
|
24
|
+
# Features for this strategy
|
|
25
|
+
FEATURES = %i[
|
|
26
|
+
long_running_job
|
|
27
|
+
virtual_partitions
|
|
28
|
+
].freeze
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
# Manual offset management enabled
|
|
19
|
+
module Mom
|
|
20
|
+
include Default
|
|
21
|
+
|
|
22
|
+
# Features for this strategy
|
|
23
|
+
FEATURES = %i[
|
|
24
|
+
manual_offset_management
|
|
25
|
+
].freeze
|
|
26
|
+
|
|
27
|
+
# When mom is enabled, we do not mark messages as consumed after processing
|
|
28
|
+
def handle_after_consume
|
|
29
|
+
coordinator.on_finished do
|
|
30
|
+
return if revoked?
|
|
31
|
+
|
|
32
|
+
if coordinator.success?
|
|
33
|
+
coordinator.pause_tracker.reset
|
|
34
|
+
else
|
|
35
|
+
pause(coordinator.seek_offset)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
# Just Virtual Partitions enabled
|
|
19
|
+
module Vp
|
|
20
|
+
# This flow is exactly the same as the default one because the default one is wrapper
|
|
21
|
+
# with `coordinator#on_finished`
|
|
22
|
+
include Default
|
|
23
|
+
|
|
24
|
+
# Features for this strategy
|
|
25
|
+
FEATURES = %i[
|
|
26
|
+
virtual_partitions
|
|
27
|
+
].freeze
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
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
|
+
# Selector of appropriate processing strategy matching topic combinations
|
|
18
|
+
# When using Karafka Pro, there is a different set of strategies than for regular, as there
|
|
19
|
+
# are different features.
|
|
20
|
+
class StrategySelector
|
|
21
|
+
def initialize
|
|
22
|
+
# We load them once for performance reasons not to do too many lookups
|
|
23
|
+
@available_strategies = Strategies
|
|
24
|
+
.constants
|
|
25
|
+
.delete_if { |k| k == :Base }
|
|
26
|
+
.map { |k| Strategies.const_get(k) }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# @param topic [Karafka::Routing::Topic] topic with settings based on which we find
|
|
30
|
+
# the strategy
|
|
31
|
+
# @return [Module] module with proper strategy
|
|
32
|
+
def find(topic)
|
|
33
|
+
feature_set = features_map(topic)
|
|
34
|
+
|
|
35
|
+
@available_strategies.find do |strategy|
|
|
36
|
+
strategy::FEATURES.sort == feature_set
|
|
37
|
+
end || raise(Errors::StrategyNotFoundError, topic.name)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
# Builds features map used to find matching processing strategy
|
|
43
|
+
#
|
|
44
|
+
# @param topic [Karafka::Routing::Topic]
|
|
45
|
+
# @return [Array<Symbol>]
|
|
46
|
+
def features_map(topic)
|
|
47
|
+
[
|
|
48
|
+
topic.active_job? ? :active_job : nil,
|
|
49
|
+
topic.long_running_job? ? :long_running_job : nil,
|
|
50
|
+
topic.manual_offset_management? ? :manual_offset_management : nil,
|
|
51
|
+
topic.virtual_partitions? ? :virtual_partitions : nil,
|
|
52
|
+
topic.dead_letter_queue? ? :dead_letter_queue : nil
|
|
53
|
+
].compact.sort
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
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
|
#
|
|
@@ -11,10 +13,11 @@
|
|
|
11
13
|
|
|
12
14
|
module Karafka
|
|
13
15
|
module Pro
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
module Routing
|
|
17
|
+
module Features
|
|
18
|
+
# Base class for all the Pro features
|
|
19
|
+
class Base < Karafka::Routing::Features::Base
|
|
20
|
+
end
|
|
18
21
|
end
|
|
19
22
|
end
|
|
20
23
|
end
|
|
@@ -0,0 +1,49 @@
|
|
|
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 Routing
|
|
17
|
+
module Features
|
|
18
|
+
class DeadLetterQueue < Base
|
|
19
|
+
# Extended rules for dead letter queue settings
|
|
20
|
+
class Contract < Contracts::Base
|
|
21
|
+
configure do |config|
|
|
22
|
+
config.error_messages = YAML.safe_load(
|
|
23
|
+
File.read(
|
|
24
|
+
File.join(Karafka.gem_root, 'config', 'errors.yml')
|
|
25
|
+
)
|
|
26
|
+
).fetch('en').fetch('validations').fetch('pro_topic')
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Make sure that we don't use DLQ with VP
|
|
30
|
+
# Using those two would cause many issues because the offset within VP is not
|
|
31
|
+
# manageable so in scenarios where we would fail on the last message, we would move by
|
|
32
|
+
# one and try again and fail, and move by one and try again and fail and so on...
|
|
33
|
+
virtual do |data, errors|
|
|
34
|
+
next unless errors.empty?
|
|
35
|
+
|
|
36
|
+
dead_letter_queue = data[:dead_letter_queue]
|
|
37
|
+
virtual_partitions = data[:virtual_partitions]
|
|
38
|
+
|
|
39
|
+
next unless dead_letter_queue[:active]
|
|
40
|
+
next unless virtual_partitions[:active]
|
|
41
|
+
|
|
42
|
+
[[%i[dead_letter_queue], :not_with_virtual_partitions]]
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
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
|
#
|
|
@@ -11,18 +13,13 @@
|
|
|
11
13
|
|
|
12
14
|
module Karafka
|
|
13
15
|
module Pro
|
|
14
|
-
# Pro routing components
|
|
15
16
|
module Routing
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
each do |consumer_group|
|
|
24
|
-
::Karafka::Pro::Contracts::ConsumerGroup.new.validate!(consumer_group.to_h)
|
|
25
|
-
end
|
|
17
|
+
module Features
|
|
18
|
+
# Enhanced Dead Letter Queue
|
|
19
|
+
#
|
|
20
|
+
# This version behaves similar to the regular version but provides ordering warranties and
|
|
21
|
+
# allows for batch skipping
|
|
22
|
+
class DeadLetterQueue < Base
|
|
26
23
|
end
|
|
27
24
|
end
|
|
28
25
|
end
|
|
@@ -0,0 +1,28 @@
|
|
|
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 Routing
|
|
17
|
+
module Features
|
|
18
|
+
class LongRunningJob < Base
|
|
19
|
+
# Long-Running Jobs configuration
|
|
20
|
+
Config = Struct.new(
|
|
21
|
+
:active,
|
|
22
|
+
keyword_init: true
|
|
23
|
+
) { alias_method :active?, :active }
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
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 Routing
|
|
17
|
+
module Features
|
|
18
|
+
class LongRunningJob < Base
|
|
19
|
+
# Rules around manual offset management settings
|
|
20
|
+
class Contract < Contracts::Base
|
|
21
|
+
configure do |config|
|
|
22
|
+
config.error_messages = YAML.safe_load(
|
|
23
|
+
File.read(
|
|
24
|
+
File.join(Karafka.gem_root, 'config', 'errors.yml')
|
|
25
|
+
)
|
|
26
|
+
).fetch('en').fetch('validations').fetch('pro_topic')
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
nested(:long_running_job) do
|
|
30
|
+
required(:active) { |val| [true, false].include?(val) }
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
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 Routing
|
|
17
|
+
module Features
|
|
18
|
+
class LongRunningJob < Base
|
|
19
|
+
# Long-Running Jobs topic API extensions
|
|
20
|
+
module Topic
|
|
21
|
+
# @param active [Boolean] do we want to enable long-running job feature for this topic
|
|
22
|
+
def long_running_job(active = false)
|
|
23
|
+
@long_running_job ||= Config.new(active: active)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# @return [Boolean] is a given job on a topic a long-running one
|
|
27
|
+
def long_running_job?
|
|
28
|
+
long_running_job.active?
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# @return [Hash] topic with all its native configuration options plus lrj
|
|
32
|
+
def to_h
|
|
33
|
+
super.merge(
|
|
34
|
+
long_running_job: long_running_job.to_h
|
|
35
|
+
).freeze
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
# Namespace for Pro routing enhancements
|
|
17
|
+
module Routing
|
|
18
|
+
# Namespace for additional Pro features
|
|
19
|
+
module Features
|
|
20
|
+
# Long-Running Jobs feature config and DSL namespace.
|
|
21
|
+
#
|
|
22
|
+
# Long-Running Jobs allow you to run Karafka jobs beyond `max.poll.interval.ms`
|
|
23
|
+
class LongRunningJob < Base
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|