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
@@ -10,7 +10,7 @@ module Karafka
|
|
10
10
|
# code here, as this is not a frequently used tracker. It is active only once per batch in
|
11
11
|
# case of long-running-jobs and upon errors.
|
12
12
|
class Pause < Base
|
13
|
-
attr_reader :
|
13
|
+
attr_reader :attempt
|
14
14
|
|
15
15
|
# @param timeout [Integer] how long should we wait when anything went wrong (in ms)
|
16
16
|
# @param max_timeout [Integer, nil] if exponential is on, what is the max value we can reach
|
@@ -19,26 +19,29 @@ module Karafka
|
|
19
19
|
# timeout value
|
20
20
|
# @return [Karafka::TimeTrackers::Pause]
|
21
21
|
# @example
|
22
|
-
#
|
22
|
+
# options = { timeout: 1000, max_timeout: 1000, exponential_backoff: false }
|
23
|
+
# pause = Karafka::TimeTrackers::Pause.new(**options)
|
23
24
|
# pause.expired? #=> true
|
24
25
|
# pause.paused? #=> false
|
25
26
|
# pause.pause
|
27
|
+
# pause.increment
|
26
28
|
# sleep(1.1)
|
27
29
|
# pause.paused? #=> true
|
28
30
|
# pause.expired? #=> true
|
29
|
-
# pause.
|
31
|
+
# pause.attempt #=> 1
|
30
32
|
# pause.pause
|
31
|
-
# pause.
|
33
|
+
# pause.increment
|
34
|
+
# pause.attempt #=> 2
|
32
35
|
# pause.paused? #=> true
|
33
36
|
# pause.expired? #=> false
|
34
37
|
# pause.resume
|
35
|
-
# pause.
|
38
|
+
# pause.attempt #=> 2
|
36
39
|
# pause.paused? #=> false
|
37
40
|
# pause.reset
|
38
|
-
# pause.
|
41
|
+
# pause.attempt #=> 0
|
39
42
|
def initialize(timeout:, max_timeout:, exponential_backoff:)
|
40
43
|
@started_at = nil
|
41
|
-
@
|
44
|
+
@attempt = 0
|
42
45
|
@timeout = timeout
|
43
46
|
@max_timeout = max_timeout
|
44
47
|
@exponential_backoff = exponential_backoff
|
@@ -47,7 +50,7 @@ module Karafka
|
|
47
50
|
end
|
48
51
|
|
49
52
|
# Pauses the processing from now till the end of the interval (backoff or non-backoff)
|
50
|
-
# and records the
|
53
|
+
# and records the attempt.
|
51
54
|
# @param timeout [Integer] timeout value in milliseconds that overwrites the default timeout
|
52
55
|
# @note Providing this value can be useful when we explicitly want to pause for a certain
|
53
56
|
# period of time, outside of any regular pausing logic
|
@@ -55,7 +58,13 @@ module Karafka
|
|
55
58
|
@mutex.synchronize do
|
56
59
|
@started_at = now
|
57
60
|
@ends_at = @started_at + timeout
|
58
|
-
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Increments the number of attempt by 1
|
65
|
+
def increment
|
66
|
+
@mutex.synchronize do
|
67
|
+
@attempt += 1
|
59
68
|
end
|
60
69
|
end
|
61
70
|
|
@@ -88,10 +97,10 @@ module Karafka
|
|
88
97
|
end
|
89
98
|
end
|
90
99
|
|
91
|
-
# Resets the pause
|
100
|
+
# Resets the pause attempt count.
|
92
101
|
def reset
|
93
102
|
@mutex.synchronize do
|
94
|
-
@
|
103
|
+
@attempt = 0
|
95
104
|
end
|
96
105
|
end
|
97
106
|
|
@@ -100,7 +109,7 @@ module Karafka
|
|
100
109
|
# Computers the exponential backoff
|
101
110
|
# @return [Integer] backoff in milliseconds
|
102
111
|
def backoff_interval
|
103
|
-
backoff_factor = @exponential_backoff ? 2**@
|
112
|
+
backoff_factor = @exponential_backoff ? 2**@attempt : 1
|
104
113
|
|
105
114
|
timeout = backoff_factor * @timeout
|
106
115
|
|
data/lib/karafka/version.rb
CHANGED
data/lib/karafka.rb
CHANGED
@@ -86,17 +86,13 @@ end
|
|
86
86
|
loader = Zeitwerk::Loader.for_gem
|
87
87
|
# Do not load Rails extensions by default, this will be handled by Railtie if they are needed
|
88
88
|
loader.ignore(Karafka.gem_root.join('lib/active_job'))
|
89
|
-
|
90
|
-
|
91
|
-
require 'karafka-license'
|
92
|
-
rescue LoadError
|
93
|
-
# Do not load pro components if we cannot load the license
|
94
|
-
# This is a preliminary check so autoload works as expected
|
95
|
-
# Later on the licenser will make sure to setup all the needed components anyhow
|
96
|
-
loader.ignore(Karafka.gem_root.join('lib/karafka/pro'))
|
97
|
-
end
|
98
|
-
|
89
|
+
# Do not load pro components as they will be loaded if needed and allowed
|
90
|
+
loader.ignore(Karafka.core_root.join('pro/'))
|
99
91
|
# Do not load vendors instrumentation components. Those need to be required manually if needed
|
100
|
-
loader.ignore(Karafka.
|
92
|
+
loader.ignore(Karafka.core_root.join('instrumentation/vendors'))
|
101
93
|
loader.setup
|
102
94
|
loader.eager_load
|
95
|
+
|
96
|
+
# This will load features but since Pro are not loaded automatically, they will not be visible
|
97
|
+
# nor included here
|
98
|
+
::Karafka::Routing::Features::Base.load_all
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: karafka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maciej Mensfeld
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
Qf04B9ceLUaC4fPVEz10FyobjaFoY4i32xRto3XnrzeAgfEe4swLq8bQsR3w/EF3
|
36
36
|
MGU0FeSV2Yj7Xc2x/7BzLK8xQn5l7Yy75iPF+KP3vVmDHnNl
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2022-
|
38
|
+
date: 2022-11-09 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: karafka-core
|
@@ -150,6 +150,7 @@ files:
|
|
150
150
|
- bin/create_token
|
151
151
|
- bin/integrations
|
152
152
|
- bin/karafka
|
153
|
+
- bin/rspecs
|
153
154
|
- bin/scenario
|
154
155
|
- bin/stress_many
|
155
156
|
- bin/stress_one
|
@@ -165,7 +166,6 @@ files:
|
|
165
166
|
- lib/karafka/active_job/dispatcher.rb
|
166
167
|
- lib/karafka/active_job/job_extensions.rb
|
167
168
|
- lib/karafka/active_job/job_options_contract.rb
|
168
|
-
- lib/karafka/active_job/routing/extensions.rb
|
169
169
|
- lib/karafka/admin.rb
|
170
170
|
- lib/karafka/app.rb
|
171
171
|
- lib/karafka/base_consumer.rb
|
@@ -186,8 +186,8 @@ files:
|
|
186
186
|
- lib/karafka/contracts/base.rb
|
187
187
|
- lib/karafka/contracts/config.rb
|
188
188
|
- lib/karafka/contracts/consumer_group.rb
|
189
|
-
- lib/karafka/contracts/consumer_group_topic.rb
|
190
189
|
- lib/karafka/contracts/server_cli_options.rb
|
190
|
+
- lib/karafka/contracts/topic.rb
|
191
191
|
- lib/karafka/embedded.rb
|
192
192
|
- lib/karafka/env.rb
|
193
193
|
- lib/karafka/errors.rb
|
@@ -204,6 +204,7 @@ files:
|
|
204
204
|
- lib/karafka/instrumentation/proctitle_listener.rb
|
205
205
|
- lib/karafka/instrumentation/vendors/datadog/dashboard.json
|
206
206
|
- lib/karafka/instrumentation/vendors/datadog/listener.rb
|
207
|
+
- lib/karafka/instrumentation/vendors/datadog/logger_listener.rb
|
207
208
|
- lib/karafka/licenser.rb
|
208
209
|
- lib/karafka/messages/batch_metadata.rb
|
209
210
|
- lib/karafka/messages/builders/batch_metadata.rb
|
@@ -220,9 +221,6 @@ files:
|
|
220
221
|
- lib/karafka/pro/active_job/dispatcher.rb
|
221
222
|
- lib/karafka/pro/active_job/job_options_contract.rb
|
222
223
|
- lib/karafka/pro/base_consumer.rb
|
223
|
-
- lib/karafka/pro/contracts/base.rb
|
224
|
-
- lib/karafka/pro/contracts/consumer_group.rb
|
225
|
-
- lib/karafka/pro/contracts/consumer_group_topic.rb
|
226
224
|
- lib/karafka/pro/loader.rb
|
227
225
|
- lib/karafka/pro/performance_tracker.rb
|
228
226
|
- lib/karafka/pro/processing/coordinator.rb
|
@@ -230,8 +228,35 @@ files:
|
|
230
228
|
- lib/karafka/pro/processing/jobs_builder.rb
|
231
229
|
- lib/karafka/pro/processing/partitioner.rb
|
232
230
|
- lib/karafka/pro/processing/scheduler.rb
|
233
|
-
- lib/karafka/pro/
|
234
|
-
- lib/karafka/pro/
|
231
|
+
- lib/karafka/pro/processing/strategies/aj_dlq_lrj_mom.rb
|
232
|
+
- lib/karafka/pro/processing/strategies/aj_dlq_mom.rb
|
233
|
+
- lib/karafka/pro/processing/strategies/aj_lrj_mom.rb
|
234
|
+
- lib/karafka/pro/processing/strategies/aj_lrj_mom_vp.rb
|
235
|
+
- lib/karafka/pro/processing/strategies/aj_mom.rb
|
236
|
+
- lib/karafka/pro/processing/strategies/aj_mom_vp.rb
|
237
|
+
- lib/karafka/pro/processing/strategies/base.rb
|
238
|
+
- lib/karafka/pro/processing/strategies/default.rb
|
239
|
+
- lib/karafka/pro/processing/strategies/dlq.rb
|
240
|
+
- lib/karafka/pro/processing/strategies/dlq_lrj.rb
|
241
|
+
- lib/karafka/pro/processing/strategies/dlq_lrj_mom.rb
|
242
|
+
- lib/karafka/pro/processing/strategies/dlq_mom.rb
|
243
|
+
- lib/karafka/pro/processing/strategies/lrj.rb
|
244
|
+
- lib/karafka/pro/processing/strategies/lrj_mom.rb
|
245
|
+
- lib/karafka/pro/processing/strategies/lrj_vp.rb
|
246
|
+
- lib/karafka/pro/processing/strategies/mom.rb
|
247
|
+
- lib/karafka/pro/processing/strategies/vp.rb
|
248
|
+
- lib/karafka/pro/processing/strategy_selector.rb
|
249
|
+
- lib/karafka/pro/routing/features/base.rb
|
250
|
+
- lib/karafka/pro/routing/features/dead_letter_queue.rb
|
251
|
+
- lib/karafka/pro/routing/features/dead_letter_queue/contract.rb
|
252
|
+
- lib/karafka/pro/routing/features/long_running_job.rb
|
253
|
+
- lib/karafka/pro/routing/features/long_running_job/config.rb
|
254
|
+
- lib/karafka/pro/routing/features/long_running_job/contract.rb
|
255
|
+
- lib/karafka/pro/routing/features/long_running_job/topic.rb
|
256
|
+
- lib/karafka/pro/routing/features/virtual_partitions.rb
|
257
|
+
- lib/karafka/pro/routing/features/virtual_partitions/config.rb
|
258
|
+
- lib/karafka/pro/routing/features/virtual_partitions/contract.rb
|
259
|
+
- lib/karafka/pro/routing/features/virtual_partitions/topic.rb
|
235
260
|
- lib/karafka/process.rb
|
236
261
|
- lib/karafka/processing/coordinator.rb
|
237
262
|
- lib/karafka/processing/coordinators_buffer.rb
|
@@ -246,12 +271,35 @@ files:
|
|
246
271
|
- lib/karafka/processing/partitioner.rb
|
247
272
|
- lib/karafka/processing/result.rb
|
248
273
|
- lib/karafka/processing/scheduler.rb
|
274
|
+
- lib/karafka/processing/strategies/aj_dlq_mom.rb
|
275
|
+
- lib/karafka/processing/strategies/aj_mom.rb
|
276
|
+
- lib/karafka/processing/strategies/base.rb
|
277
|
+
- lib/karafka/processing/strategies/default.rb
|
278
|
+
- lib/karafka/processing/strategies/dlq.rb
|
279
|
+
- lib/karafka/processing/strategies/dlq_mom.rb
|
280
|
+
- lib/karafka/processing/strategies/mom.rb
|
281
|
+
- lib/karafka/processing/strategy_selector.rb
|
249
282
|
- lib/karafka/processing/worker.rb
|
250
283
|
- lib/karafka/processing/workers_batch.rb
|
251
284
|
- lib/karafka/railtie.rb
|
252
285
|
- lib/karafka/routing/builder.rb
|
253
286
|
- lib/karafka/routing/consumer_group.rb
|
254
287
|
- lib/karafka/routing/consumer_mapper.rb
|
288
|
+
- lib/karafka/routing/features/active_job.rb
|
289
|
+
- lib/karafka/routing/features/active_job/builder.rb
|
290
|
+
- lib/karafka/routing/features/active_job/config.rb
|
291
|
+
- lib/karafka/routing/features/active_job/contract.rb
|
292
|
+
- lib/karafka/routing/features/active_job/topic.rb
|
293
|
+
- lib/karafka/routing/features/base.rb
|
294
|
+
- lib/karafka/routing/features/base/expander.rb
|
295
|
+
- lib/karafka/routing/features/dead_letter_queue.rb
|
296
|
+
- lib/karafka/routing/features/dead_letter_queue/config.rb
|
297
|
+
- lib/karafka/routing/features/dead_letter_queue/contract.rb
|
298
|
+
- lib/karafka/routing/features/dead_letter_queue/topic.rb
|
299
|
+
- lib/karafka/routing/features/manual_offset_management.rb
|
300
|
+
- lib/karafka/routing/features/manual_offset_management/config.rb
|
301
|
+
- lib/karafka/routing/features/manual_offset_management/contract.rb
|
302
|
+
- lib/karafka/routing/features/manual_offset_management/topic.rb
|
255
303
|
- lib/karafka/routing/proxy.rb
|
256
304
|
- lib/karafka/routing/router.rb
|
257
305
|
- lib/karafka/routing/subscription_group.rb
|
metadata.gz.sig
CHANGED
Binary file
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Karafka
|
4
|
-
# ActiveJob related Karafka stuff
|
5
|
-
module ActiveJob
|
6
|
-
# Karafka routing ActiveJob related components
|
7
|
-
module Routing
|
8
|
-
# Routing extensions for ActiveJob
|
9
|
-
module Extensions
|
10
|
-
# This method simplifies routes definition for ActiveJob topics / queues by auto-injecting
|
11
|
-
# the consumer class
|
12
|
-
# @param name [String, Symbol] name of the topic where ActiveJobs jobs should go
|
13
|
-
# @param block [Proc] block that we can use for some extra configuration
|
14
|
-
def active_job_topic(name, &block)
|
15
|
-
topic(name) do
|
16
|
-
consumer App.config.internal.active_job.consumer_class
|
17
|
-
|
18
|
-
next unless block
|
19
|
-
|
20
|
-
instance_eval(&block)
|
21
|
-
|
22
|
-
target.tags << :active_job
|
23
|
-
|
24
|
-
# This is handled by our custom ActiveJob consumer
|
25
|
-
# Without this, default behaviour would cause messages to skip upon shutdown as the
|
26
|
-
# offset would be committed for the last message
|
27
|
-
manual_offset_management true
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# This Karafka component is a Pro component.
|
4
|
-
# All of the commercial components are present in the lib/karafka/pro directory of this
|
5
|
-
# repository and their usage requires commercial license agreement.
|
6
|
-
#
|
7
|
-
# Karafka has also commercial-friendly license, commercial support and commercial components.
|
8
|
-
#
|
9
|
-
# By sending a pull request to the pro components, you are agreeing to transfer the copyright of
|
10
|
-
# your code to Maciej Mensfeld.
|
11
|
-
|
12
|
-
module Karafka
|
13
|
-
module Pro
|
14
|
-
module Contracts
|
15
|
-
# Contract for validating correct Pro components setup on a consumer group and topic levels
|
16
|
-
class ConsumerGroup < Base
|
17
|
-
virtual do |data, errors|
|
18
|
-
next unless errors.empty?
|
19
|
-
next unless data.key?(:topics)
|
20
|
-
|
21
|
-
fetched_errors = []
|
22
|
-
|
23
|
-
data.fetch(:topics).each do |topic|
|
24
|
-
ConsumerGroupTopic.new.call(topic).errors.each do |key, value|
|
25
|
-
fetched_errors << [[topic, key].flatten, value]
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
fetched_errors
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# This Karafka component is a Pro component.
|
4
|
-
# All of the commercial components are present in the lib/karafka/pro directory of this
|
5
|
-
# repository and their usage requires commercial license agreement.
|
6
|
-
#
|
7
|
-
# Karafka has also commercial-friendly license, commercial support and commercial components.
|
8
|
-
#
|
9
|
-
# By sending a pull request to the pro components, you are agreeing to transfer the copyright of
|
10
|
-
# your code to Maciej Mensfeld.
|
11
|
-
|
12
|
-
module Karafka
|
13
|
-
module Pro
|
14
|
-
module Contracts
|
15
|
-
# Contract for validating correct Pro components setup on a topic levels
|
16
|
-
class ConsumerGroupTopic < Base
|
17
|
-
configure do |config|
|
18
|
-
config.error_messages = YAML.safe_load(
|
19
|
-
File.read(
|
20
|
-
File.join(Karafka.gem_root, 'config', 'errors.yml')
|
21
|
-
)
|
22
|
-
).fetch('en').fetch('validations').fetch('pro_consumer_group_topic')
|
23
|
-
end
|
24
|
-
|
25
|
-
nested(:virtual_partitions) do
|
26
|
-
required(:active) { |val| [true, false].include?(val) }
|
27
|
-
required(:partitioner) { |val| val.nil? || val.respond_to?(:call) }
|
28
|
-
required(:max_partitions) { |val| val.is_a?(Integer) && val >= 1 }
|
29
|
-
end
|
30
|
-
|
31
|
-
virtual do |data, errors|
|
32
|
-
next unless errors.empty?
|
33
|
-
next if data[:consumer] < Karafka::Pro::BaseConsumer
|
34
|
-
|
35
|
-
[[%i[consumer], :consumer_format]]
|
36
|
-
end
|
37
|
-
|
38
|
-
# When virtual partitions are defined, partitioner needs to respond to `#call` and it
|
39
|
-
# cannot be nil
|
40
|
-
virtual do |data, errors|
|
41
|
-
next unless errors.empty?
|
42
|
-
|
43
|
-
virtual_partitions = data[:virtual_partitions]
|
44
|
-
|
45
|
-
next unless virtual_partitions[:active]
|
46
|
-
next if virtual_partitions[:partitioner].respond_to?(:call)
|
47
|
-
|
48
|
-
[[%i[virtual_partitions partitioner], :respond_to_call]]
|
49
|
-
end
|
50
|
-
|
51
|
-
# Make sure that manual offset management is not used together with Virtual Partitions
|
52
|
-
# This would not make any sense as there would be edge cases related to skipping
|
53
|
-
# messages even if there were errors.
|
54
|
-
virtual do |data, errors|
|
55
|
-
next unless errors.empty?
|
56
|
-
|
57
|
-
virtual_partitions = data[:virtual_partitions]
|
58
|
-
manual_offset_management = data[:manual_offset_management]
|
59
|
-
|
60
|
-
next unless virtual_partitions[:active]
|
61
|
-
next unless manual_offset_management
|
62
|
-
next if data[:tags].include?(:active_job)
|
63
|
-
|
64
|
-
[[%i[manual_offset_management], :not_with_virtual_partitions]]
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# This Karafka component is a Pro component.
|
4
|
-
# All of the commercial components are present in the lib/karafka/pro directory of this
|
5
|
-
# repository and their usage requires commercial license agreement.
|
6
|
-
#
|
7
|
-
# Karafka has also commercial-friendly license, commercial support and commercial components.
|
8
|
-
#
|
9
|
-
# By sending a pull request to the pro components, you are agreeing to transfer the copyright of
|
10
|
-
# your code to Maciej Mensfeld.
|
11
|
-
|
12
|
-
module Karafka
|
13
|
-
module Pro
|
14
|
-
# Pro routing components
|
15
|
-
module Routing
|
16
|
-
# Routing extensions that allow to configure some extra PRO routing options
|
17
|
-
module TopicExtensions
|
18
|
-
# Internal representation of the virtual partitions settings and configuration
|
19
|
-
# This allows us to abstract away things in a nice manner
|
20
|
-
#
|
21
|
-
# For features with more options than just on/off we use this approach as it simplifies
|
22
|
-
# the code. We do not use it for all not to create unneeded complexity
|
23
|
-
VirtualPartitions = Struct.new(
|
24
|
-
:active,
|
25
|
-
:partitioner,
|
26
|
-
:max_partitions,
|
27
|
-
keyword_init: true
|
28
|
-
) { alias_method :active?, :active }
|
29
|
-
|
30
|
-
class << self
|
31
|
-
# @param base [Class] class we extend
|
32
|
-
def prepended(base)
|
33
|
-
base.attr_accessor :long_running_job
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# @param max_partitions [Integer] max number of virtual partitions that can come out of the
|
38
|
-
# single distribution flow. When set to more than the Karafka threading, will create
|
39
|
-
# more work than workers. When less, can ensure we have spare resources to process other
|
40
|
-
# things in parallel.
|
41
|
-
# @param partitioner [nil, #call] nil or callable partitioner
|
42
|
-
# @return [VirtualPartitions] method that allows to set the virtual partitions details
|
43
|
-
# during the routing configuration and then allows to retrieve it
|
44
|
-
def virtual_partitions(
|
45
|
-
max_partitions: Karafka::App.config.concurrency,
|
46
|
-
partitioner: nil
|
47
|
-
)
|
48
|
-
@virtual_partitions ||= VirtualPartitions.new(
|
49
|
-
active: !partitioner.nil?,
|
50
|
-
max_partitions: max_partitions,
|
51
|
-
partitioner: partitioner
|
52
|
-
)
|
53
|
-
end
|
54
|
-
|
55
|
-
# @return [Boolean] are virtual partitions enabled for given topic
|
56
|
-
def virtual_partitions?
|
57
|
-
virtual_partitions.active?
|
58
|
-
end
|
59
|
-
|
60
|
-
# @return [Boolean] is a given job on a topic a long-running one
|
61
|
-
def long_running_job?
|
62
|
-
@long_running_job || false
|
63
|
-
end
|
64
|
-
|
65
|
-
# @return [Hash] hash with topic details and the extensions details
|
66
|
-
def to_h
|
67
|
-
super.merge(
|
68
|
-
virtual_partitions: virtual_partitions.to_h
|
69
|
-
)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|