karafka 2.0.28 → 2.0.30
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/CHANGELOG.md +16 -1
- data/Gemfile.lock +11 -10
- data/README.md +5 -3
- data/bin/karafka +1 -19
- data/bin/verify_license_integrity +2 -0
- data/karafka.gemspec +1 -1
- data/lib/karafka/cli/base.rb +20 -0
- data/lib/karafka/cli/console.rb +13 -8
- data/lib/karafka/cli/server.rb +50 -4
- data/lib/karafka/contracts/server_cli_options.rb +50 -48
- data/lib/karafka/instrumentation/callbacks/error.rb +1 -0
- data/lib/karafka/railtie.rb +2 -9
- data/lib/karafka/routing/activity_manager.rb +84 -0
- data/lib/karafka/routing/consumer_group.rb +1 -4
- data/lib/karafka/routing/subscription_group.rb +1 -4
- data/lib/karafka/routing/topic.rb +1 -4
- data/lib/karafka/server.rb +1 -1
- data/lib/karafka/setup/config.rb +2 -6
- data/lib/karafka/templates/karafka.rb.erb +6 -0
- data/lib/karafka/version.rb +1 -1
- data/lib/karafka.rb +13 -0
- data.tar.gz.sig +0 -0
- metadata +5 -4
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c983b3fbf07db3e91f3c051a8b4de4b2d88619877fbf66a4e434e38bf67c96b
|
4
|
+
data.tar.gz: babb3c513e6bb3fd0610363e3bbd9e7fcf07b1820f02fdd80ccacc8a109aab08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea000c13a834ffba97c1837fa1f19dabbf78dbe8958354a8200bb5d2c0940852343521e6740113e07890f97a7e6edd108d8595a66688c4c14dbf313e86ec715f
|
7
|
+
data.tar.gz: 81ae980ef7950c6cae7d1bea2751d1826e5bbf4c1384be4736af895977fb7ff38f70c24a9b7b248cb18744e042ffb0ba0dc154171c29dcc73262733d87c31ea1
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,23 @@
|
|
1
1
|
# Karafka framework changelog
|
2
2
|
|
3
|
+
## 2.0.30 (2022-01-31)
|
4
|
+
- [Improvement] Alias `--consumer-groups` with `--include-consumer-groups`
|
5
|
+
- [Improvement] Alias `--subscription-groups` with `--include-subscription-groups`
|
6
|
+
- [Improvement] Alias `--topics` with `--include-topics`
|
7
|
+
- [Improvement] Introduce `--exclude-consumer-groups` for ability to exclude certain consumer groups from running
|
8
|
+
- [Improvement] Introduce `--exclude-subscription-groups` for ability to exclude certain subscription groups from running
|
9
|
+
- [Improvement] Introduce `--exclude-topics` for ability to exclude certain topics from running
|
10
|
+
|
11
|
+
## 2.0.29 (2023-01-30)
|
12
|
+
- [Improvement] Make sure, that the `Karafka#producer` instance has the `LoggerListener` enabled in the install template, so Karafka by default prints both consumer and producer info.
|
13
|
+
- [Improvement] Extract the code loading capabilities of Karafka console from the executable, so web can use it to provide CLI commands.
|
14
|
+
- [Fix] Fix for: running karafka console results in NameError with Rails (#1280)
|
15
|
+
- [Fix] Make sure, that the `caller` for async errors is being published.
|
16
|
+
- [Change] Make sure that WaterDrop `2.4.10` or higher is used with this release to support Web-UI.
|
17
|
+
|
3
18
|
## 2.0.28 (2023-01-25)
|
4
19
|
- **[Feature]** Provide the ability to use Dead Letter Queue with Virtual Partitions.
|
5
|
-
- [Improvement] Collapse Virtual Partitions upon retryable error to a single partition. This allows dead letter queue to operate and mitigate issues arising from work virtualization. This removes uncertainties upon errors that can be retried and processed. Affects given topic partition virtualization only for multi-topic and
|
20
|
+
- [Improvement] Collapse Virtual Partitions upon retryable error to a single partition. This allows dead letter queue to operate and mitigate issues arising from work virtualization. This removes uncertainties upon errors that can be retried and processed. Affects given topic partition virtualization only for multi-topic and multi-partition parallelization. It also minimizes potential "flickering" where given data set has potentially many corrupted messages. The collapse will last until all the messages from the collective corrupted batch are processed. After that, virtualization will resume.
|
6
21
|
- [Improvement] Introduce `#collapsed?` consumer method available for consumers using Virtual Partitions.
|
7
22
|
- [Improvement] Allow for customization of DLQ dispatched message details in Pro (#1266) via the `#enhance_dlq_message` consumer method.
|
8
23
|
- [Improvement] Include `original_consumer_group` in the DLQ dispatched messages in Pro.
|
data/Gemfile.lock
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
karafka (2.0.
|
4
|
+
karafka (2.0.30)
|
5
5
|
karafka-core (>= 2.0.9, < 3.0.0)
|
6
6
|
thor (>= 0.20)
|
7
|
-
waterdrop (>= 2.4.
|
7
|
+
waterdrop (>= 2.4.10, < 3.0.0)
|
8
8
|
zeitwerk (~> 2.3)
|
9
9
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
activejob (7.0.4.
|
14
|
-
activesupport (= 7.0.4.
|
13
|
+
activejob (7.0.4.2)
|
14
|
+
activesupport (= 7.0.4.2)
|
15
15
|
globalid (>= 0.3.6)
|
16
|
-
activesupport (7.0.4.
|
16
|
+
activesupport (7.0.4.2)
|
17
17
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
18
|
i18n (>= 1.6, < 2)
|
19
19
|
minitest (>= 5.1)
|
20
20
|
tzinfo (~> 2.0)
|
21
21
|
byebug (11.1.3)
|
22
|
-
concurrent-ruby (1.
|
22
|
+
concurrent-ruby (1.2.0)
|
23
23
|
diff-lcs (1.5.0)
|
24
24
|
docile (1.4.0)
|
25
25
|
factory_bot (6.2.1)
|
26
26
|
activesupport (>= 5.0.0)
|
27
27
|
ffi (1.15.5)
|
28
|
-
globalid (1.0
|
28
|
+
globalid (1.1.0)
|
29
29
|
activesupport (>= 5.0)
|
30
30
|
i18n (1.12.0)
|
31
31
|
concurrent-ruby (~> 1.0)
|
@@ -59,14 +59,15 @@ GEM
|
|
59
59
|
simplecov-html (0.12.3)
|
60
60
|
simplecov_json_formatter (0.1.4)
|
61
61
|
thor (1.2.1)
|
62
|
-
tzinfo (2.0.
|
62
|
+
tzinfo (2.0.6)
|
63
63
|
concurrent-ruby (~> 1.0)
|
64
|
-
waterdrop (2.4.
|
64
|
+
waterdrop (2.4.10)
|
65
65
|
karafka-core (>= 2.0.9, < 3.0.0)
|
66
66
|
zeitwerk (~> 2.3)
|
67
67
|
zeitwerk (2.6.6)
|
68
68
|
|
69
69
|
PLATFORMS
|
70
|
+
arm64-darwin-21
|
70
71
|
x86_64-linux
|
71
72
|
|
72
73
|
DEPENDENCIES
|
@@ -78,4 +79,4 @@ DEPENDENCIES
|
|
78
79
|
simplecov
|
79
80
|
|
80
81
|
BUNDLED WITH
|
81
|
-
2.4.
|
82
|
+
2.4.5
|
data/README.md
CHANGED
@@ -10,6 +10,7 @@
|
|
10
10
|
|
11
11
|
Karafka is a Ruby and Rails multi-threaded efficient Kafka processing framework that:
|
12
12
|
|
13
|
+
- Has a built-in [Web UI](https://karafka.io/docs/Web-UI-Features/) providing a convenient way to monitor and manage Karafka-based applications.
|
13
14
|
- Supports parallel processing in [multiple threads](https://karafka.io/docs/Concurrency-and-multithreading) (also for a [single topic partition](https://karafka.io/docs/Pro-Virtual-Partitions) work)
|
14
15
|
- [Automatically integrates](https://karafka.io/docs/Integrating-with-Ruby-on-Rails-and-other-frameworks#integrating-with-ruby-on-rails) with Ruby on Rails
|
15
16
|
- Has [ActiveJob backend](https://karafka.io/docs/Active-Job) support (including [ordered jobs](https://karafka.io/docs/Pro-Enhanced-Active-Job#ordered-jobs))
|
@@ -58,7 +59,8 @@ We also maintain many [integration specs](https://github.com/karafka/karafka/tre
|
|
58
59
|
1. Add and install Karafka:
|
59
60
|
|
60
61
|
```bash
|
61
|
-
|
62
|
+
# Make sure to install Karafka 2.0
|
63
|
+
bundle add karafka --version ">= 2.0.28"
|
62
64
|
|
63
65
|
bundle exec karafka install
|
64
66
|
```
|
@@ -82,11 +84,11 @@ bundle exec karafka server
|
|
82
84
|
|
83
85
|
## Want to Upgrade? LGPL is not for you? Want to help?
|
84
86
|
|
85
|
-
I also sell Karafka Pro subscriptions. It includes a commercial-friendly license, priority support, architecture consultations, and high throughput data processing-related features (virtual partitions, long-running jobs, and more).
|
87
|
+
I also sell Karafka Pro subscriptions. It includes a commercial-friendly license, priority support, architecture consultations, enhanced Web UI and high throughput data processing-related features (virtual partitions, long-running jobs, and more).
|
86
88
|
|
87
89
|
**20%** of the income will be distributed back to other OSS projects that Karafka uses under the hood.
|
88
90
|
|
89
|
-
Help me provide high-quality open-source software. Please see the Karafka [homepage](https://karafka.io) for more details.
|
91
|
+
Help me provide high-quality open-source software. Please see the Karafka [homepage](https://karafka.io/#become-pro) for more details.
|
90
92
|
|
91
93
|
## Support
|
92
94
|
|
data/bin/karafka
CHANGED
@@ -6,24 +6,6 @@ require 'karafka'
|
|
6
6
|
# our bin/karafka cli
|
7
7
|
ENV['KARAFKA_CLI'] = 'true'
|
8
8
|
|
9
|
-
|
10
|
-
# Karafka app setup, routes, etc
|
11
|
-
if File.exist?(Karafka.boot_file)
|
12
|
-
rails_env_rb = File.join(Dir.pwd, 'config/environment.rb')
|
13
|
-
|
14
|
-
# Load Rails environment file that starts Rails, so we can reference consumers and other things
|
15
|
-
# from `karafka.rb` file. This will work only for Rails, for non-rails a manual setup is needed
|
16
|
-
require rails_env_rb if Kernel.const_defined?(:Rails) && File.exist?(rails_env_rb)
|
17
|
-
|
18
|
-
require Karafka.boot_file.to_s
|
19
|
-
else
|
20
|
-
# However when it is unavailable, we still want to be able to run help command
|
21
|
-
# and install command as they don't require configured app itself to run
|
22
|
-
raise(
|
23
|
-
Karafka::Errors::MissingBootFileError,
|
24
|
-
Karafka.boot_file
|
25
|
-
) unless %w[-h install].include?(ARGV[0])
|
26
|
-
end
|
27
|
-
|
9
|
+
Karafka::Cli::Base.load
|
28
10
|
Karafka::Cli.prepare
|
29
11
|
Karafka::Cli.start
|
@@ -11,6 +11,8 @@ set -e
|
|
11
11
|
if [ "$MODE" != "after" ]; then
|
12
12
|
# Check the remote license prior to bundle installing
|
13
13
|
curl \
|
14
|
+
--retry 5 \
|
15
|
+
--retry-delay 1 \
|
14
16
|
--fail \
|
15
17
|
-u $KARAFKA_PRO_USERNAME:$KARAFKA_PRO_PASSWORD \
|
16
18
|
https://gems.karafka.io/gems/karafka-license-$KARAFKA_PRO_VERSION.gem \
|
data/karafka.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
|
24
24
|
spec.add_dependency 'karafka-core', '>= 2.0.9', '< 3.0.0'
|
25
25
|
spec.add_dependency 'thor', '>= 0.20'
|
26
|
-
spec.add_dependency 'waterdrop', '>= 2.4.
|
26
|
+
spec.add_dependency 'waterdrop', '>= 2.4.10', '< 3.0.0'
|
27
27
|
spec.add_dependency 'zeitwerk', '~> 2.3'
|
28
28
|
|
29
29
|
if $PROGRAM_NAME.end_with?('gem')
|
data/lib/karafka/cli/base.rb
CHANGED
@@ -34,6 +34,26 @@ module Karafka
|
|
34
34
|
end
|
35
35
|
|
36
36
|
class << self
|
37
|
+
# Loads proper environment with what is needed to run the CLI
|
38
|
+
def load
|
39
|
+
# If there is a boot file, we need to require it as we expect it to contain
|
40
|
+
# Karafka app setup, routes, etc
|
41
|
+
if File.exist?(::Karafka.boot_file)
|
42
|
+
rails_env_rb = File.join(Dir.pwd, 'config/environment.rb')
|
43
|
+
|
44
|
+
# Load Rails environment file that starts Rails, so we can reference consumers and
|
45
|
+
# other things from `karafka.rb` file. This will work only for Rails, for non-rails
|
46
|
+
# a manual setup is needed
|
47
|
+
require rails_env_rb if Kernel.const_defined?(:Rails) && File.exist?(rails_env_rb)
|
48
|
+
|
49
|
+
require Karafka.boot_file.to_s
|
50
|
+
# However when it is unavailable, we still want to be able to run help command
|
51
|
+
# and install command as they don't require configured app itself to run
|
52
|
+
elsif %w[-h install].none? { |cmd| cmd == ARGV[0] }
|
53
|
+
raise ::Karafka::Errors::MissingBootFileError, ::Karafka.boot_file
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
37
57
|
# Allows to set options for Thor cli
|
38
58
|
# @see https://github.com/erikhuda/thor
|
39
59
|
# @param option Single option details
|
data/lib/karafka/cli/console.rb
CHANGED
@@ -9,22 +9,27 @@ module Karafka
|
|
9
9
|
option aliases: 'c'
|
10
10
|
|
11
11
|
class << self
|
12
|
-
# @return [String] Console executing command
|
12
|
+
# @return [String] Console executing command for non-Rails setup
|
13
13
|
# @example
|
14
14
|
# Karafka::Cli::Console.command #=> 'KARAFKA_CONSOLE=true bundle exec irb...'
|
15
|
-
def
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
def console
|
16
|
+
"IRBRC='#{Karafka.gem_root}/.console_irbrc' bundle exec irb -r #{Karafka.boot_file}"
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [String] Console executing command for Rails setup
|
20
|
+
# @note In case of Rails, it has its own console, hence we can just defer to it
|
21
|
+
def rails_console
|
22
|
+
'bundle exec rails console'
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
24
26
|
# Start the Karafka console
|
25
27
|
def call
|
26
28
|
cli.info
|
27
|
-
|
29
|
+
|
30
|
+
command = ::Karafka.rails? ? self.class.rails_console : self.class.console
|
31
|
+
|
32
|
+
exec "KARAFKA_CONSOLE=true #{command}"
|
28
33
|
end
|
29
34
|
end
|
30
35
|
end
|
data/lib/karafka/cli/server.rb
CHANGED
@@ -7,27 +7,73 @@ module Karafka
|
|
7
7
|
class Server < Base
|
8
8
|
include Helpers::Colorize
|
9
9
|
|
10
|
+
# Types of things we can include / exclude from the routing via the CLI options
|
11
|
+
SUPPORTED_TYPES = ::Karafka::Routing::ActivityManager::SUPPORTED_TYPES
|
12
|
+
|
13
|
+
private_constant :SUPPORTED_TYPES
|
14
|
+
|
10
15
|
desc 'Start the Karafka server (short-cut alias: "s")'
|
16
|
+
|
11
17
|
option aliases: 's'
|
18
|
+
|
19
|
+
# Thor does not work well with many aliases combinations, hence we remap the aliases
|
20
|
+
# by ourselves in the code
|
12
21
|
option :consumer_groups, type: :array, default: [], aliases: :g
|
13
22
|
option :subscription_groups, type: :array, default: []
|
14
23
|
option :topics, type: :array, default: []
|
15
24
|
|
25
|
+
%i[
|
26
|
+
include
|
27
|
+
exclude
|
28
|
+
].each do |action|
|
29
|
+
SUPPORTED_TYPES.each do |type|
|
30
|
+
option(
|
31
|
+
"#{action}_#{type}",
|
32
|
+
type: :array,
|
33
|
+
default: []
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
16
38
|
# Start the Karafka server
|
17
39
|
def call
|
18
40
|
# Print our banner and info in the dev mode
|
19
41
|
print_marketing_info if Karafka::App.env.development?
|
20
42
|
|
21
|
-
|
22
|
-
|
23
|
-
active_routing_config.subscription_groups = cli.options[:subscription_groups]
|
24
|
-
active_routing_config.topics = cli.options[:topics]
|
43
|
+
register_inclusions(cli)
|
44
|
+
register_exclusions(cli)
|
25
45
|
|
26
46
|
Karafka::Server.run
|
27
47
|
end
|
28
48
|
|
29
49
|
private
|
30
50
|
|
51
|
+
# Registers things we want to include (if defined)
|
52
|
+
# @param cli [Karafka::Cli] Thor cli handler
|
53
|
+
def register_inclusions(cli)
|
54
|
+
activities = ::Karafka::App.config.internal.routing.activity_manager
|
55
|
+
|
56
|
+
SUPPORTED_TYPES.each do |type|
|
57
|
+
v1 = cli.options[type] || []
|
58
|
+
v2 = cli.options[:"include_#{type}"] || []
|
59
|
+
names = v1 + v2
|
60
|
+
|
61
|
+
names.each { |name| activities.include(type, name) }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Registers things we want to exclude (if defined)
|
66
|
+
# @param cli [Karafka::Cli] Thor cli handler
|
67
|
+
def register_exclusions(cli)
|
68
|
+
activities = ::Karafka::App.config.internal.routing.activity_manager
|
69
|
+
|
70
|
+
activities.class::SUPPORTED_TYPES.each do |type|
|
71
|
+
names = cli.options[:"exclude_#{type}"] || []
|
72
|
+
|
73
|
+
names.each { |name| activities.exclude(type, name) }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
31
77
|
# Prints marketing info
|
32
78
|
def print_marketing_info
|
33
79
|
Karafka.logger.info Info::BANNER
|
@@ -12,69 +12,71 @@ module Karafka
|
|
12
12
|
).fetch('en').fetch('validations').fetch('server_cli_options')
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
%i[
|
16
|
+
include
|
17
|
+
exclude
|
18
|
+
].each do |action|
|
19
|
+
optional(:"#{action}_consumer_groups") { |cg| cg.is_a?(Array) }
|
20
|
+
optional(:"#{action}_subscription_groups") { |sg| sg.is_a?(Array) }
|
21
|
+
optional(:"#{action}_topics") { |topics| topics.is_a?(Array) }
|
18
22
|
|
19
|
-
|
20
|
-
|
21
|
-
next unless data.key?(:consumer_groups)
|
23
|
+
virtual do |data, errors|
|
24
|
+
next unless errors.empty?
|
22
25
|
|
23
|
-
|
26
|
+
value = data.fetch(:"#{action}_consumer_groups")
|
24
27
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
28
|
+
# If there were no consumer_groups declared in the server cli, it means that we will
|
29
|
+
# run all of them and no need to validate them here at all
|
30
|
+
next if value.empty?
|
31
|
+
next if (value - Karafka::App.consumer_groups.map(&:name)).empty?
|
29
32
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
+
# Found unknown consumer groups
|
34
|
+
[[[:"#{action}_consumer_groups"], :consumer_groups_inclusion]]
|
35
|
+
end
|
33
36
|
|
34
|
-
|
35
|
-
|
36
|
-
next unless data.key?(:subscription_groups)
|
37
|
+
virtual do |data, errors|
|
38
|
+
next unless errors.empty?
|
37
39
|
|
38
|
-
|
40
|
+
value = data.fetch(:"#{action}_subscription_groups")
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
|
42
|
+
# If there were no subscription_groups declared in the server cli, it means that we will
|
43
|
+
# run all of them and no need to validate them here at all
|
44
|
+
next if value.empty?
|
43
45
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
subscription_groups = Karafka::App
|
47
|
+
.consumer_groups
|
48
|
+
.map(&:subscription_groups)
|
49
|
+
.flatten
|
50
|
+
.map(&:name)
|
49
51
|
|
50
|
-
|
52
|
+
next if (value - subscription_groups).empty?
|
51
53
|
|
52
|
-
|
53
|
-
|
54
|
-
|
54
|
+
# Found unknown subscription groups
|
55
|
+
[[[:"#{action}_subscription_groups"], :subscription_groups_inclusion]]
|
56
|
+
end
|
55
57
|
|
56
|
-
|
57
|
-
|
58
|
-
next unless data.key?(:topics)
|
58
|
+
virtual do |data, errors|
|
59
|
+
next unless errors.empty?
|
59
60
|
|
60
|
-
|
61
|
+
value = data.fetch(:"#{action}_topics")
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
63
|
+
# If there were no topics declared in the server cli, it means that we will
|
64
|
+
# run all of them and no need to validate them here at all
|
65
|
+
next if value.empty?
|
65
66
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
67
|
+
topics = Karafka::App
|
68
|
+
.consumer_groups
|
69
|
+
.map(&:subscription_groups)
|
70
|
+
.flatten
|
71
|
+
.map(&:topics)
|
72
|
+
.map { |gtopics| gtopics.map(&:name) }
|
73
|
+
.flatten
|
73
74
|
|
74
|
-
|
75
|
+
next if (value - topics).empty?
|
75
76
|
|
76
|
-
|
77
|
-
|
77
|
+
# Found unknown topics
|
78
|
+
[[[:"#{action}_topics"], :topics_inclusion]]
|
79
|
+
end
|
78
80
|
end
|
79
81
|
|
80
82
|
# Makes sure we have anything to subscribe to when we start the server
|
@@ -83,7 +85,7 @@ module Karafka
|
|
83
85
|
|
84
86
|
next unless Karafka::App.subscription_groups.empty?
|
85
87
|
|
86
|
-
[[%i[
|
88
|
+
[[%i[include_topics], :topics_missing]]
|
87
89
|
end
|
88
90
|
end
|
89
91
|
end
|
data/lib/karafka/railtie.rb
CHANGED
@@ -2,14 +2,7 @@
|
|
2
2
|
|
3
3
|
# This file contains Railtie for auto-configuration
|
4
4
|
|
5
|
-
rails
|
6
|
-
|
7
|
-
begin
|
8
|
-
# Do not load Rails again if already loaded
|
9
|
-
Object.const_defined?('Rails::Railtie') || require('rails')
|
10
|
-
|
11
|
-
rails = true
|
12
|
-
rescue LoadError
|
5
|
+
unless Karafka.rails?
|
13
6
|
# Without defining this in any way, Zeitwerk ain't happy so we do it that way
|
14
7
|
module Karafka
|
15
8
|
class Railtie
|
@@ -17,7 +10,7 @@ rescue LoadError
|
|
17
10
|
end
|
18
11
|
end
|
19
12
|
|
20
|
-
if rails
|
13
|
+
if Karafka.rails?
|
21
14
|
# Load ActiveJob adapter
|
22
15
|
require 'active_job/karafka'
|
23
16
|
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Karafka
|
4
|
+
module Routing
|
5
|
+
# Allows us to get track of which consumer groups, subscription groups and topics are enabled
|
6
|
+
# or disabled via CLI
|
7
|
+
class ActivityManager
|
8
|
+
# Supported types of inclusions and exclusions
|
9
|
+
SUPPORTED_TYPES = %i[
|
10
|
+
consumer_groups
|
11
|
+
subscription_groups
|
12
|
+
topics
|
13
|
+
].freeze
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@included = Hash.new { |h, k| h[k] = [] }
|
17
|
+
@excluded = Hash.new { |h, k| h[k] = [] }
|
18
|
+
end
|
19
|
+
|
20
|
+
# Adds resource to included/active
|
21
|
+
# @param type [Symbol] type for inclusion
|
22
|
+
# @param name [String] name of the element
|
23
|
+
def include(type, name)
|
24
|
+
validate!(type)
|
25
|
+
|
26
|
+
@included[type] << name
|
27
|
+
end
|
28
|
+
|
29
|
+
# Adds resource to excluded
|
30
|
+
# @param type [Symbol] type for inclusion
|
31
|
+
# @param name [String] name of the element
|
32
|
+
def exclude(type, name)
|
33
|
+
validate!(type)
|
34
|
+
|
35
|
+
@excluded[type] << name
|
36
|
+
end
|
37
|
+
|
38
|
+
# @param type [Symbol] type for inclusion
|
39
|
+
# @param name [String] name of the element
|
40
|
+
# @return [Boolean] is the given resource active or not
|
41
|
+
def active?(type, name)
|
42
|
+
validate!(type)
|
43
|
+
|
44
|
+
included = @included[type]
|
45
|
+
excluded = @excluded[type]
|
46
|
+
|
47
|
+
# If nothing defined, all active by default
|
48
|
+
return true if included.empty? && excluded.empty?
|
49
|
+
# Inclusion supersedes exclusion in case someone wrote both
|
50
|
+
return true if !included.empty? && included.include?(name)
|
51
|
+
|
52
|
+
# If there are exclusions but our is not excluded and no inclusions or included, it's ok
|
53
|
+
!excluded.empty? &&
|
54
|
+
!excluded.include?(name) &&
|
55
|
+
(included.empty? || included.include?(name))
|
56
|
+
end
|
57
|
+
|
58
|
+
# @return [Hash] accumulated data in a hash for validations
|
59
|
+
def to_h
|
60
|
+
(
|
61
|
+
SUPPORTED_TYPES.map { |type| ["include_#{type}".to_sym, @included[type]] } +
|
62
|
+
SUPPORTED_TYPES.map { |type| ["exclude_#{type}".to_sym, @excluded[type]] }
|
63
|
+
).to_h
|
64
|
+
end
|
65
|
+
|
66
|
+
# Clears the manager
|
67
|
+
def clear
|
68
|
+
@included.clear
|
69
|
+
@excluded.clear
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
# Checks if the type we want to register is supported
|
75
|
+
#
|
76
|
+
# @param type [Symbol] type for inclusion
|
77
|
+
def validate!(type)
|
78
|
+
return if SUPPORTED_TYPES.include?(type)
|
79
|
+
|
80
|
+
raise(::Karafka::Errors::UnsupportedCaseError, type)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -31,10 +31,7 @@ module Karafka
|
|
31
31
|
|
32
32
|
# @return [Boolean] true if this consumer group should be active in our current process
|
33
33
|
def active?
|
34
|
-
|
35
|
-
|
36
|
-
# When empty it means no groups were specified, hence all should be used
|
37
|
-
cgs.empty? || cgs.include?(name)
|
34
|
+
Karafka::App.config.internal.routing.activity_manager.active?(:consumer_groups, name)
|
38
35
|
end
|
39
36
|
|
40
37
|
# Builds a topic representation inside of a current consumer group route
|
@@ -58,10 +58,7 @@ module Karafka
|
|
58
58
|
|
59
59
|
# @return [Boolean] is this subscription group one of active once
|
60
60
|
def active?
|
61
|
-
|
62
|
-
|
63
|
-
# When empty it means no groups were specified, hence all should be used
|
64
|
-
sgs.empty? || sgs.include?(name)
|
61
|
+
Karafka::App.config.internal.routing.activity_manager.active?(:subscription_groups, name)
|
65
62
|
end
|
66
63
|
|
67
64
|
private
|
@@ -87,10 +87,7 @@ module Karafka
|
|
87
87
|
# Never active if disabled via routing
|
88
88
|
return false unless @active
|
89
89
|
|
90
|
-
|
91
|
-
|
92
|
-
# When empty it means no topics were specified, hence all should be used
|
93
|
-
topics.empty? || topics.include?(name)
|
90
|
+
Karafka::App.config.internal.routing.activity_manager.active?(:topics, name)
|
94
91
|
end
|
95
92
|
|
96
93
|
# @return [Hash] hash with all the topic attributes
|
data/lib/karafka/server.rb
CHANGED
@@ -33,7 +33,7 @@ module Karafka
|
|
33
33
|
# We cannot validate this during the start because config needs to be populated and routes
|
34
34
|
# need to be defined.
|
35
35
|
Contracts::ServerCliOptions.new.validate!(
|
36
|
-
Karafka::App.config.internal.routing.
|
36
|
+
Karafka::App.config.internal.routing.activity_manager.to_h
|
37
37
|
)
|
38
38
|
|
39
39
|
process.on_sigint { stop }
|
data/lib/karafka/setup/config.rb
CHANGED
@@ -111,12 +111,8 @@ module Karafka
|
|
111
111
|
setting :subscription_groups_builder, default: Routing::SubscriptionGroupsBuilder.new
|
112
112
|
|
113
113
|
# Internally assigned list of limits on routings active for the current process
|
114
|
-
# This
|
115
|
-
setting :
|
116
|
-
setting :consumer_groups, default: [].freeze
|
117
|
-
setting :subscription_groups, default: [].freeze
|
118
|
-
setting :topics, default: [].freeze
|
119
|
-
end
|
114
|
+
# This can be altered by the CLI command
|
115
|
+
setting :activity_manager, default: Routing::ActivityManager.new
|
120
116
|
end
|
121
117
|
|
122
118
|
setting :processing do
|
@@ -40,6 +40,12 @@ class KarafkaApp < Karafka::App
|
|
40
40
|
Karafka.monitor.subscribe(Karafka::Instrumentation::LoggerListener.new)
|
41
41
|
# Karafka.monitor.subscribe(Karafka::Instrumentation::ProctitleListener.new)
|
42
42
|
|
43
|
+
# This logger prints the producer development info using the Karafka logger.
|
44
|
+
# It is similar to the consumer logger listener but producer oriented.
|
45
|
+
Karafka.producer.monitor.subscribe(
|
46
|
+
WaterDrop::Instrumentation::LoggerListener.new(Karafka.logger)
|
47
|
+
)
|
48
|
+
|
43
49
|
routes.draw do
|
44
50
|
<% if rails? -%>
|
45
51
|
# Uncomment this if you use Karafka with ActiveJob
|
data/lib/karafka/version.rb
CHANGED
data/lib/karafka.rb
CHANGED
@@ -70,6 +70,19 @@ module Karafka
|
|
70
70
|
App.config.license.token != false
|
71
71
|
end
|
72
72
|
|
73
|
+
# @return [Boolean] Do we run within/with Rails. We use this to initialize Railtie and proxy
|
74
|
+
# the console invocation to Rails
|
75
|
+
def rails?
|
76
|
+
return @rails if instance_variable_defined?('@rails')
|
77
|
+
|
78
|
+
# Do not load Rails again if already loaded
|
79
|
+
Object.const_defined?('Rails::Railtie') || require('rails')
|
80
|
+
|
81
|
+
@rails = true
|
82
|
+
rescue LoadError
|
83
|
+
@rails = false
|
84
|
+
end
|
85
|
+
|
73
86
|
# @return [String] path to a default file that contains booting procedure etc
|
74
87
|
# @note By default it is a file called 'karafka.rb' but it can be specified as you wish if you
|
75
88
|
# have Karafka that is merged into a Sinatra/Rails app and karafka.rb is taken.
|
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.30
|
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: 2023-01-
|
38
|
+
date: 2023-01-31 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: karafka-core
|
@@ -77,7 +77,7 @@ dependencies:
|
|
77
77
|
requirements:
|
78
78
|
- - ">="
|
79
79
|
- !ruby/object:Gem::Version
|
80
|
-
version: 2.4.
|
80
|
+
version: 2.4.10
|
81
81
|
- - "<"
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: 3.0.0
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
requirements:
|
88
88
|
- - ">="
|
89
89
|
- !ruby/object:Gem::Version
|
90
|
-
version: 2.4.
|
90
|
+
version: 2.4.10
|
91
91
|
- - "<"
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: 3.0.0
|
@@ -289,6 +289,7 @@ files:
|
|
289
289
|
- lib/karafka/processing/worker.rb
|
290
290
|
- lib/karafka/processing/workers_batch.rb
|
291
291
|
- lib/karafka/railtie.rb
|
292
|
+
- lib/karafka/routing/activity_manager.rb
|
292
293
|
- lib/karafka/routing/builder.rb
|
293
294
|
- lib/karafka/routing/consumer_group.rb
|
294
295
|
- lib/karafka/routing/consumer_mapper.rb
|
metadata.gz.sig
CHANGED
Binary file
|