karafka 1.4.0 → 1.4.5
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.tar.gz.sig +0 -0
- data/.github/workflows/ci.yml +24 -2
- data/.ruby-version +1 -1
- data/CHANGELOG.md +18 -0
- data/Gemfile.lock +64 -68
- data/README.md +5 -5
- data/config/errors.yml +2 -0
- data/karafka.gemspec +1 -2
- data/lib/karafka/assignment_strategies/round_robin.rb +13 -0
- data/lib/karafka/attributes_map.rb +1 -0
- data/lib/karafka/cli.rb +8 -0
- data/lib/karafka/cli/base.rb +4 -4
- data/lib/karafka/cli/install.rb +1 -1
- data/lib/karafka/cli/missingno.rb +19 -0
- data/lib/karafka/cli/server.rb +8 -8
- data/lib/karafka/connection/api_adapter.rb +10 -12
- data/lib/karafka/connection/builder.rb +6 -1
- data/lib/karafka/connection/client.rb +6 -4
- data/lib/karafka/contracts.rb +1 -1
- data/lib/karafka/contracts/consumer_group.rb +8 -3
- data/lib/karafka/helpers/class_matcher.rb +1 -1
- data/lib/karafka/instrumentation/logger.rb +6 -10
- data/lib/karafka/instrumentation/stdout_listener.rb +2 -2
- data/lib/karafka/routing/builder.rb +1 -0
- data/lib/karafka/routing/consumer_group.rb +5 -3
- data/lib/karafka/server.rb +1 -1
- data/lib/karafka/setup/config.rb +3 -0
- data/lib/karafka/templates/karafka.rb.erb +1 -1
- data/lib/karafka/version.rb +1 -1
- metadata +6 -18
- 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: cece2722193b4847122f13f76ed00c8452e8905324c1c15fa957c0ae1668d7be
|
4
|
+
data.tar.gz: e3dd2266eab30ffb325b3e3a7a76bd508ad36823814e59f60954498c284c9060
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e761e7c4de55708bffb6228ab6a30e55a6797fa9210d337a433626fdfb637f73af436f58b0dfe05e7f0fc7c6982a21b8038c5508e998aa7594e70888a181e688
|
7
|
+
data.tar.gz: 4c0bc1792a6e0e35bb43f5c13e37639f3327037b38d892cd3bc6f048e9a621cbc6569d7923bb08d21f9892495aa22f8eb53fc02c93bc3528b48ceeac129622a5
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/.github/workflows/ci.yml
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
name: ci
|
2
2
|
|
3
3
|
on:
|
4
|
+
pull_request:
|
4
5
|
push:
|
5
6
|
schedule:
|
6
7
|
- cron: '0 1 * * *'
|
@@ -8,15 +9,16 @@ on:
|
|
8
9
|
jobs:
|
9
10
|
specs:
|
10
11
|
runs-on: ubuntu-latest
|
12
|
+
needs: diffend
|
11
13
|
strategy:
|
12
14
|
fail-fast: false
|
13
15
|
matrix:
|
14
16
|
ruby:
|
17
|
+
- '3.0'
|
15
18
|
- '2.7'
|
16
19
|
- '2.6'
|
17
|
-
- '2.5'
|
18
20
|
include:
|
19
|
-
- ruby: '
|
21
|
+
- ruby: '3.0'
|
20
22
|
coverage: 'true'
|
21
23
|
steps:
|
22
24
|
- uses: actions/checkout@v2
|
@@ -40,6 +42,26 @@ jobs:
|
|
40
42
|
env:
|
41
43
|
GITHUB_COVERAGE: ${{matrix.coverage}}
|
42
44
|
run: bundle exec rspec
|
45
|
+
|
46
|
+
diffend:
|
47
|
+
runs-on: ubuntu-latest
|
48
|
+
strategy:
|
49
|
+
fail-fast: false
|
50
|
+
steps:
|
51
|
+
- uses: actions/checkout@v2
|
52
|
+
with:
|
53
|
+
fetch-depth: 0
|
54
|
+
- name: Set up Ruby
|
55
|
+
uses: ruby/setup-ruby@v1
|
56
|
+
with:
|
57
|
+
ruby-version: 3.0
|
58
|
+
- name: Install latest bundler
|
59
|
+
run: gem install bundler --no-document
|
60
|
+
- name: Install Diffend plugin
|
61
|
+
run: bundle plugin install diffend
|
62
|
+
- name: Bundle Secure
|
63
|
+
run: bundle secure
|
64
|
+
|
43
65
|
coditsu:
|
44
66
|
runs-on: ubuntu-latest
|
45
67
|
strategy:
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.0.1
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
# Karafka framework changelog
|
2
2
|
|
3
|
+
## 1.4.5 (2021-06-16)
|
4
|
+
- Fixup logger checks for non-writeable logfile (ojab)
|
5
|
+
- #689 - Update the stdout initialization message for framework initialization
|
6
|
+
|
7
|
+
## 1.4.4 (2021-04-19)
|
8
|
+
- Remove Ruby 2.5 support and update minimum Ruby requirement to 2.6
|
9
|
+
- Remove rake dependency
|
10
|
+
|
11
|
+
## 1.4.3 (2021-03-24)
|
12
|
+
- Fixes for Ruby 3.0 compatibility
|
13
|
+
|
14
|
+
## 1.4.2 (2021-02-16)
|
15
|
+
- Rescue Errno::EROFS in ensure_dir_exists (unasuke)
|
16
|
+
|
17
|
+
## 1.4.1 (2020-12-04)
|
18
|
+
- Return non-zero exit code when printing usage
|
19
|
+
- Add support for :assignment_strategy for consumers
|
20
|
+
|
3
21
|
## 1.4.0 (2020-09-05)
|
4
22
|
- Rename `Karafka::Params::Metadata` to `Karafka::Params::BatchMetadata`
|
5
23
|
` Rename consumer `#metadata` to `#batch_metadata`
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
karafka (1.4.
|
4
|
+
karafka (1.4.5)
|
5
5
|
dry-configurable (~> 0.8)
|
6
6
|
dry-inflector (~> 0.1)
|
7
7
|
dry-monitor (~> 0.3)
|
8
8
|
dry-validation (~> 1.2)
|
9
9
|
envlogic (~> 1.1)
|
10
10
|
irb (~> 1.0)
|
11
|
-
rake (>= 11.3)
|
12
11
|
ruby-kafka (>= 1.0.0)
|
13
12
|
thor (>= 0.20)
|
14
13
|
waterdrop (~> 1.4.0)
|
@@ -17,116 +16,113 @@ PATH
|
|
17
16
|
GEM
|
18
17
|
remote: https://rubygems.org/
|
19
18
|
specs:
|
20
|
-
activesupport (6.
|
19
|
+
activesupport (6.1.3.2)
|
21
20
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
22
|
-
i18n (>=
|
23
|
-
minitest (
|
24
|
-
tzinfo (~>
|
25
|
-
zeitwerk (~> 2.
|
21
|
+
i18n (>= 1.6, < 2)
|
22
|
+
minitest (>= 5.1)
|
23
|
+
tzinfo (~> 2.0)
|
24
|
+
zeitwerk (~> 2.3)
|
26
25
|
byebug (11.1.3)
|
27
|
-
concurrent-ruby (1.1.
|
28
|
-
delivery_boy (1.0
|
29
|
-
king_konf (~> 0
|
26
|
+
concurrent-ruby (1.1.9)
|
27
|
+
delivery_boy (1.1.0)
|
28
|
+
king_konf (~> 1.0)
|
30
29
|
ruby-kafka (~> 1.0)
|
31
30
|
diff-lcs (1.4.4)
|
32
|
-
digest-crc (0.6.
|
33
|
-
rake (
|
34
|
-
docile (1.
|
35
|
-
dry-configurable (0.
|
31
|
+
digest-crc (0.6.3)
|
32
|
+
rake (>= 12.0.0, < 14.0.0)
|
33
|
+
docile (1.4.0)
|
34
|
+
dry-configurable (0.12.1)
|
36
35
|
concurrent-ruby (~> 1.0)
|
37
|
-
dry-core (~> 0.
|
38
|
-
|
39
|
-
dry-container (0.7.2)
|
36
|
+
dry-core (~> 0.5, >= 0.5.0)
|
37
|
+
dry-container (0.8.0)
|
40
38
|
concurrent-ruby (~> 1.0)
|
41
39
|
dry-configurable (~> 0.1, >= 0.1.3)
|
42
|
-
dry-core (0.
|
40
|
+
dry-core (0.6.0)
|
43
41
|
concurrent-ruby (~> 1.0)
|
44
42
|
dry-equalizer (0.3.0)
|
45
|
-
dry-events (0.
|
43
|
+
dry-events (0.3.0)
|
46
44
|
concurrent-ruby (~> 1.0)
|
47
|
-
dry-core (~> 0.
|
48
|
-
dry-equalizer (~> 0.2)
|
45
|
+
dry-core (~> 0.5, >= 0.5)
|
49
46
|
dry-inflector (0.2.0)
|
50
|
-
dry-initializer (3.0.
|
51
|
-
dry-logic (1.0
|
47
|
+
dry-initializer (3.0.4)
|
48
|
+
dry-logic (1.2.0)
|
52
49
|
concurrent-ruby (~> 1.0)
|
53
|
-
dry-core (~> 0.
|
54
|
-
|
55
|
-
dry-monitor (0.3.2)
|
50
|
+
dry-core (~> 0.5, >= 0.5)
|
51
|
+
dry-monitor (0.4.0)
|
56
52
|
dry-configurable (~> 0.5)
|
57
|
-
dry-core (~> 0.
|
58
|
-
dry-equalizer (~> 0.2)
|
53
|
+
dry-core (~> 0.5, >= 0.5)
|
59
54
|
dry-events (~> 0.2)
|
60
|
-
dry-schema (1.
|
55
|
+
dry-schema (1.6.2)
|
61
56
|
concurrent-ruby (~> 1.0)
|
62
57
|
dry-configurable (~> 0.8, >= 0.8.3)
|
63
|
-
dry-core (~> 0.
|
64
|
-
dry-equalizer (~> 0.2)
|
58
|
+
dry-core (~> 0.5, >= 0.5)
|
65
59
|
dry-initializer (~> 3.0)
|
66
60
|
dry-logic (~> 1.0)
|
67
|
-
dry-types (~> 1.
|
68
|
-
dry-types (1.
|
61
|
+
dry-types (~> 1.5)
|
62
|
+
dry-types (1.5.1)
|
69
63
|
concurrent-ruby (~> 1.0)
|
70
64
|
dry-container (~> 0.3)
|
71
|
-
dry-core (~> 0.
|
72
|
-
dry-equalizer (~> 0.3)
|
65
|
+
dry-core (~> 0.5, >= 0.5)
|
73
66
|
dry-inflector (~> 0.1, >= 0.1.2)
|
74
67
|
dry-logic (~> 1.0, >= 1.0.2)
|
75
|
-
dry-validation (1.
|
68
|
+
dry-validation (1.6.0)
|
76
69
|
concurrent-ruby (~> 1.0)
|
77
70
|
dry-container (~> 0.7, >= 0.7.1)
|
78
71
|
dry-core (~> 0.4)
|
79
72
|
dry-equalizer (~> 0.2)
|
80
73
|
dry-initializer (~> 3.0)
|
81
74
|
dry-schema (~> 1.5, >= 1.5.2)
|
82
|
-
envlogic (1.1.
|
75
|
+
envlogic (1.1.3)
|
83
76
|
dry-inflector (~> 0.1)
|
84
|
-
factory_bot (6.
|
77
|
+
factory_bot (6.2.0)
|
85
78
|
activesupport (>= 5.0.0)
|
86
|
-
i18n (1.8.
|
79
|
+
i18n (1.8.10)
|
87
80
|
concurrent-ruby (~> 1.0)
|
88
|
-
io-console (0.5.
|
89
|
-
irb (1.
|
90
|
-
reline (>= 0.
|
91
|
-
king_konf (0.
|
92
|
-
minitest (5.14.
|
93
|
-
rake (13.0.
|
94
|
-
reline (0.
|
81
|
+
io-console (0.5.9)
|
82
|
+
irb (1.3.5)
|
83
|
+
reline (>= 0.1.5)
|
84
|
+
king_konf (1.0.0)
|
85
|
+
minitest (5.14.4)
|
86
|
+
rake (13.0.3)
|
87
|
+
reline (0.2.5)
|
95
88
|
io-console (~> 0.5)
|
96
|
-
rspec (3.
|
97
|
-
rspec-core (~> 3.
|
98
|
-
rspec-expectations (~> 3.
|
99
|
-
rspec-mocks (~> 3.
|
100
|
-
rspec-core (3.
|
101
|
-
rspec-support (~> 3.
|
102
|
-
rspec-expectations (3.
|
89
|
+
rspec (3.10.0)
|
90
|
+
rspec-core (~> 3.10.0)
|
91
|
+
rspec-expectations (~> 3.10.0)
|
92
|
+
rspec-mocks (~> 3.10.0)
|
93
|
+
rspec-core (3.10.1)
|
94
|
+
rspec-support (~> 3.10.0)
|
95
|
+
rspec-expectations (3.10.1)
|
103
96
|
diff-lcs (>= 1.2.0, < 2.0)
|
104
|
-
rspec-support (~> 3.
|
105
|
-
rspec-mocks (3.
|
97
|
+
rspec-support (~> 3.10.0)
|
98
|
+
rspec-mocks (3.10.2)
|
106
99
|
diff-lcs (>= 1.2.0, < 2.0)
|
107
|
-
rspec-support (~> 3.
|
108
|
-
rspec-support (3.
|
109
|
-
ruby-kafka (1.
|
100
|
+
rspec-support (~> 3.10.0)
|
101
|
+
rspec-support (3.10.2)
|
102
|
+
ruby-kafka (1.3.0)
|
110
103
|
digest-crc
|
111
|
-
simplecov (0.
|
104
|
+
simplecov (0.21.2)
|
112
105
|
docile (~> 1.1)
|
113
106
|
simplecov-html (~> 0.11)
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
107
|
+
simplecov_json_formatter (~> 0.1)
|
108
|
+
simplecov-html (0.12.3)
|
109
|
+
simplecov_json_formatter (0.1.3)
|
110
|
+
thor (1.1.0)
|
111
|
+
tzinfo (2.0.4)
|
112
|
+
concurrent-ruby (~> 1.0)
|
113
|
+
waterdrop (1.4.2)
|
120
114
|
delivery_boy (>= 0.2, < 2.x)
|
121
115
|
dry-configurable (~> 0.8)
|
122
116
|
dry-monitor (~> 0.3)
|
123
117
|
dry-validation (~> 1.2)
|
124
118
|
ruby-kafka (>= 0.7.8)
|
125
119
|
zeitwerk (~> 2.1)
|
126
|
-
zeitwerk (2.4.
|
120
|
+
zeitwerk (2.4.2)
|
127
121
|
|
128
122
|
PLATFORMS
|
129
|
-
|
123
|
+
x86_64-darwin
|
124
|
+
x86_64-darwin-19
|
125
|
+
x86_64-linux
|
130
126
|
|
131
127
|
DEPENDENCIES
|
132
128
|
byebug
|
@@ -136,4 +132,4 @@ DEPENDENCIES
|
|
136
132
|
simplecov
|
137
133
|
|
138
134
|
BUNDLED WITH
|
139
|
-
2.
|
135
|
+
2.2.20
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
![karafka logo](https://raw.githubusercontent.com/karafka/misc/master/logo/karafka_logotype_transparent2.png)
|
2
2
|
|
3
|
-
[![Build Status](https://
|
3
|
+
[![Build Status](https://github.com/karafka/karafka/actions/workflows/ci.yml/badge.svg)](https://github.com/karafka/karafka/actions/workflows/ci.yml)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/karafka.svg)](http://badge.fury.io/rb/karafka)
|
5
|
+
[![Join the chat at https://gitter.im/karafka/karafka](https://badges.gitter.im/karafka/karafka.svg)](https://gitter.im/karafka/karafka)
|
4
6
|
|
5
|
-
**Note**:
|
6
|
-
|
7
|
-
If you are looking for the documentation for Karafka `1.3.x`, it can be found [here](https://github.com/karafka/wiki/tree/1.3).
|
7
|
+
**Note**: We're finishing the new Karafka `2.0` but for now, please use `1.4`. All the documentation presented here refers to `1.4`
|
8
8
|
|
9
9
|
## About Karafka
|
10
10
|
|
@@ -72,7 +72,7 @@ Karafka framework and Karafka team are __not__ related to Kafka streaming servic
|
|
72
72
|
## References
|
73
73
|
|
74
74
|
* [Karafka framework](https://github.com/karafka/karafka)
|
75
|
-
* [Karafka
|
75
|
+
* [Karafka GitHub Actions](https://github.com/karafka/karafka/actions)
|
76
76
|
* [Karafka Coditsu](https://app.coditsu.io/karafka/repositories/karafka)
|
77
77
|
|
78
78
|
## Note on contributions
|
data/config/errors.yml
CHANGED
data/karafka.gemspec
CHANGED
@@ -23,13 +23,12 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_dependency 'dry-validation', '~> 1.2'
|
24
24
|
spec.add_dependency 'envlogic', '~> 1.1'
|
25
25
|
spec.add_dependency 'irb', '~> 1.0'
|
26
|
-
spec.add_dependency 'rake', '>= 11.3'
|
27
26
|
spec.add_dependency 'ruby-kafka', '>= 1.0.0'
|
28
27
|
spec.add_dependency 'thor', '>= 0.20'
|
29
28
|
spec.add_dependency 'waterdrop', '~> 1.4.0'
|
30
29
|
spec.add_dependency 'zeitwerk', '~> 2.1'
|
31
30
|
|
32
|
-
spec.required_ruby_version = '>= 2.
|
31
|
+
spec.required_ruby_version = '>= 2.6.0'
|
33
32
|
|
34
33
|
if $PROGRAM_NAME.end_with?('gem')
|
35
34
|
spec.signing_key = File.expand_path('~/.ssh/gem-private_key.pem')
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Karafka
|
4
|
+
# Strategies for Kafka partitions assignments
|
5
|
+
module AssignmentStrategies
|
6
|
+
# Standard RoundRobin strategy
|
7
|
+
class RoundRobin < SimpleDelegator
|
8
|
+
def initialize
|
9
|
+
super(Kafka::RoundRobinAssignmentStrategy.new)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -19,6 +19,7 @@ module Karafka
|
|
19
19
|
consumer: %i[
|
20
20
|
session_timeout offset_commit_interval offset_commit_threshold
|
21
21
|
offset_retention_time heartbeat_interval fetcher_max_queue_size
|
22
|
+
assignment_strategy
|
22
23
|
],
|
23
24
|
subscribe: %i[start_from_beginning max_bytes_per_partition],
|
24
25
|
consumption: %i[min_bytes max_bytes max_wait_time],
|
data/lib/karafka/cli.rb
CHANGED
@@ -10,6 +10,8 @@ module Karafka
|
|
10
10
|
class Cli < Thor
|
11
11
|
package_name 'Karafka'
|
12
12
|
|
13
|
+
default_task :missingno
|
14
|
+
|
13
15
|
class << self
|
14
16
|
# Loads all Cli commands into Thor framework
|
15
17
|
# This method should be executed before we run Karafka::Cli.start, otherwise we won't
|
@@ -20,6 +22,12 @@ module Karafka
|
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
25
|
+
# When there is a CLI crash, exit
|
26
|
+
# @return [true]
|
27
|
+
def exit_on_failure?
|
28
|
+
true
|
29
|
+
end
|
30
|
+
|
23
31
|
private
|
24
32
|
|
25
33
|
# @return [Array<Class>] Array with Cli action classes that can be used as commands
|
data/lib/karafka/cli/base.rb
CHANGED
@@ -43,16 +43,16 @@ module Karafka
|
|
43
43
|
end
|
44
44
|
|
45
45
|
# Allows to set description of a given cli command
|
46
|
-
# @param
|
47
|
-
def desc(
|
48
|
-
@desc ||=
|
46
|
+
# @param args [Array] All the arguments that Thor desc method accepts
|
47
|
+
def desc(*args)
|
48
|
+
@desc ||= args
|
49
49
|
end
|
50
50
|
|
51
51
|
# This method will bind a given Cli command into Karafka Cli
|
52
52
|
# This method is a wrapper to way Thor defines its commands
|
53
53
|
# @param cli_class [Karafka::Cli] Karafka cli_class
|
54
54
|
def bind_to(cli_class)
|
55
|
-
cli_class.desc name,
|
55
|
+
cli_class.desc name, *@desc
|
56
56
|
|
57
57
|
(@options || []).each { |option| cli_class.option(*option) }
|
58
58
|
|
data/lib/karafka/cli/install.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Karafka
|
4
|
+
class Cli < Thor
|
5
|
+
# Command that gets invoked when no method is provided when running the CLI
|
6
|
+
# It allows us to exit with exit code 1 instead of default 0 to indicate that something
|
7
|
+
# was missing
|
8
|
+
# @see https://github.com/karafka/karafka/issues/619
|
9
|
+
class Missingno < Base
|
10
|
+
desc 'Hidden command that gets invoked when no command is provided', hide: true
|
11
|
+
|
12
|
+
# Prints an error about the lack of command (nothing selected)
|
13
|
+
def call
|
14
|
+
Karafka.logger.error('No command provided')
|
15
|
+
exit 1
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/karafka/cli/server.rb
CHANGED
@@ -31,14 +31,6 @@ module Karafka
|
|
31
31
|
# part of the topics
|
32
32
|
Karafka::Server.consumer_groups = cli.options[:consumer_groups]
|
33
33
|
|
34
|
-
# Remove pidfile on stop, just before the server instance is going to be GCed
|
35
|
-
# We want to delay the moment in which the pidfile is removed as much as we can,
|
36
|
-
# so instead of removing it after the server stops running, we rely on the gc moment
|
37
|
-
# when this object gets removed (it is a bit later), so it is closer to the actual
|
38
|
-
# system process end. We do that, so monitoring and deployment tools that rely on a pid
|
39
|
-
# won't alarm or start new system process up until the current one is finished
|
40
|
-
ObjectSpace.define_finalizer(self, proc { send(:clean) })
|
41
|
-
|
42
34
|
Karafka::Server.run
|
43
35
|
end
|
44
36
|
|
@@ -60,6 +52,14 @@ module Karafka
|
|
60
52
|
cli.options[:pid],
|
61
53
|
'w'
|
62
54
|
) { |file| file.write(::Process.pid) }
|
55
|
+
|
56
|
+
# Remove pidfile on stop, just before the server instance is going to be GCed
|
57
|
+
# We want to delay the moment in which the pidfile is removed as much as we can,
|
58
|
+
# so instead of removing it after the server stops running, we rely on the gc moment
|
59
|
+
# when this object gets removed (it is a bit later), so it is closer to the actual
|
60
|
+
# system process end. We do that, so monitoring and deployment tools that rely on a pid
|
61
|
+
# won't alarm or start new system process up until the current one is finished
|
62
|
+
ObjectSpace.define_finalizer(self, proc { send(:clean) })
|
63
63
|
end
|
64
64
|
|
65
65
|
# Removes a pidfile (if exist)
|
@@ -48,30 +48,28 @@ module Karafka
|
|
48
48
|
|
49
49
|
# Builds all the configuration settings for kafka#consumer method
|
50
50
|
# @param consumer_group [Karafka::Routing::ConsumerGroup] consumer group details
|
51
|
-
# @return [
|
51
|
+
# @return [Hash] all the consumer keyword arguments including hash with all
|
52
52
|
# the settings required by Kafka#consumer
|
53
53
|
def consumer(consumer_group)
|
54
54
|
settings = { group_id: consumer_group.id }
|
55
55
|
settings = fetch_for(:consumer, consumer_group, settings)
|
56
|
-
|
56
|
+
sanitize(settings)
|
57
57
|
end
|
58
58
|
|
59
59
|
# Builds all the configuration settings for kafka consumer consume_each_batch and
|
60
60
|
# consume_each_message methods
|
61
61
|
# @param consumer_group [Karafka::Routing::ConsumerGroup] consumer group details
|
62
|
-
# @return [
|
63
|
-
# including
|
62
|
+
# @return [Hash] hash with all the arguments required by consuming method
|
63
|
+
# including all the settings required by
|
64
64
|
# Kafka::Consumer#consume_each_message and Kafka::Consumer#consume_each_batch method
|
65
65
|
def consumption(consumer_group)
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
automatically_mark_as_processed: consumer_group.automatically_mark_as_consumed
|
72
|
-
)
|
66
|
+
sanitize(
|
67
|
+
fetch_for(
|
68
|
+
:consumption,
|
69
|
+
consumer_group,
|
70
|
+
automatically_mark_as_processed: consumer_group.automatically_mark_as_consumed
|
73
71
|
)
|
74
|
-
|
72
|
+
)
|
75
73
|
end
|
76
74
|
|
77
75
|
# Builds all the configuration settings for kafka consumer#subscribe method
|
@@ -10,7 +10,12 @@ module Karafka
|
|
10
10
|
# to have a new Kafka client
|
11
11
|
# @return [::Kafka::Client] returns a Kafka client
|
12
12
|
def call(consumer_group)
|
13
|
-
|
13
|
+
settings = ApiAdapter.client(consumer_group)
|
14
|
+
|
15
|
+
Kafka.new(
|
16
|
+
settings[0],
|
17
|
+
**settings[1]
|
18
|
+
)
|
14
19
|
end
|
15
20
|
end
|
16
21
|
end
|
@@ -33,9 +33,9 @@ module Karafka
|
|
33
33
|
settings = ApiAdapter.consumption(consumer_group)
|
34
34
|
|
35
35
|
if consumer_group.batch_fetching
|
36
|
-
kafka_consumer.each_batch(
|
36
|
+
kafka_consumer.each_batch(**settings) { |batch| yield(batch, :batch) }
|
37
37
|
else
|
38
|
-
kafka_consumer.each_message(
|
38
|
+
kafka_consumer.each_message(**settings) { |message| yield(message, :message) }
|
39
39
|
end
|
40
40
|
# @note We catch only the processing errors as any other are considered critical (exceptions)
|
41
41
|
# and should require a client restart with a backoff
|
@@ -98,10 +98,12 @@ module Karafka
|
|
98
98
|
# @note We don't cache the connection internally because we cache kafka_consumer that uses
|
99
99
|
# kafka client object instance
|
100
100
|
@kafka_consumer ||= Builder.call(consumer_group).consumer(
|
101
|
-
|
101
|
+
**ApiAdapter.consumer(consumer_group)
|
102
102
|
).tap do |consumer|
|
103
103
|
consumer_group.topics.each do |topic|
|
104
|
-
|
104
|
+
settings = ApiAdapter.subscribe(topic)
|
105
|
+
|
106
|
+
consumer.subscribe(settings[0], **settings[1])
|
105
107
|
end
|
106
108
|
end
|
107
109
|
rescue Kafka::ConnectionError
|
data/lib/karafka/contracts.rb
CHANGED
@@ -32,6 +32,7 @@ module Karafka
|
|
32
32
|
required(:offset_retention_time).maybe(:integer)
|
33
33
|
required(:heartbeat_interval).filled { (int? | float?) & gteq?(0) }
|
34
34
|
required(:fetcher_max_queue_size).filled(:int?, gt?: 0)
|
35
|
+
required(:assignment_strategy).value(:any)
|
35
36
|
required(:connect_timeout).filled { (int? | float?) & gt?(0) }
|
36
37
|
required(:reconnect_timeout).filled { (int? | float?) & gteq?(0) }
|
37
38
|
required(:socket_timeout).filled { (int? | float?) & gt?(0) }
|
@@ -70,13 +71,13 @@ module Karafka
|
|
70
71
|
|
71
72
|
# Uri rule to check if uri is in a Karafka acceptable format
|
72
73
|
rule(:seed_brokers) do
|
73
|
-
if value
|
74
|
+
if value.is_a?(Array) && !value.all?(&method(:kafka_uri?))
|
74
75
|
key.failure(:invalid_broker_schema)
|
75
76
|
end
|
76
77
|
end
|
77
78
|
|
78
79
|
rule(:topics) do
|
79
|
-
if value
|
80
|
+
if value.is_a?(Array)
|
80
81
|
names = value.map { |topic| topic[:name] }
|
81
82
|
|
82
83
|
key.failure(:topics_names_not_unique) if names.size != names.uniq.size
|
@@ -84,7 +85,7 @@ module Karafka
|
|
84
85
|
end
|
85
86
|
|
86
87
|
rule(:topics) do
|
87
|
-
if value
|
88
|
+
if value.is_a?(Array)
|
88
89
|
value.each_with_index do |topic, index|
|
89
90
|
TOPIC_CONTRACT.call(topic).errors.each do |error|
|
90
91
|
key([:topics, index, error.path[0]]).failure(error.text)
|
@@ -93,6 +94,10 @@ module Karafka
|
|
93
94
|
end
|
94
95
|
end
|
95
96
|
|
97
|
+
rule(:assignment_strategy) do
|
98
|
+
key.failure(:does_not_respond_to_call) unless value.respond_to?(:call)
|
99
|
+
end
|
100
|
+
|
96
101
|
rule(:ssl_client_cert, :ssl_client_cert_key) do
|
97
102
|
if values[:ssl_client_cert] && !values[:ssl_client_cert_key]
|
98
103
|
key(:ssl_client_cert_key).failure(:ssl_client_cert_with_ssl_client_cert_key)
|
@@ -8,7 +8,7 @@ module Karafka
|
|
8
8
|
class ClassMatcher
|
9
9
|
# Regexp used to remove any non classy like characters that might be in the consumer
|
10
10
|
# class name (if defined dynamically, etc)
|
11
|
-
CONSTANT_REGEXP = %r{[
|
11
|
+
CONSTANT_REGEXP = %r{[?!=+\-*/\^|&\[\]<>%~\#:\s()]}.freeze
|
12
12
|
|
13
13
|
private_constant :CONSTANT_REGEXP
|
14
14
|
|
@@ -20,7 +20,6 @@ module Karafka
|
|
20
20
|
# @param _args Any arguments that we don't care about but that are needed in order to
|
21
21
|
# make this logger compatible with the default Ruby one
|
22
22
|
def initialize(*_args)
|
23
|
-
ensure_dir_exists
|
24
23
|
super(target)
|
25
24
|
self.level = ENV_MAP[Karafka.env] || ENV_MAP['default']
|
26
25
|
end
|
@@ -29,18 +28,11 @@ module Karafka
|
|
29
28
|
|
30
29
|
# @return [Karafka::Helpers::MultiDelegator] multi delegator instance
|
31
30
|
# to which we will be writing logs
|
32
|
-
# We use this approach to log stuff to file and to the
|
31
|
+
# We use this approach to log stuff to file and to the $stdout at the same time
|
33
32
|
def target
|
34
33
|
Karafka::Helpers::MultiDelegator
|
35
34
|
.delegate(:write, :close)
|
36
|
-
.to(
|
37
|
-
end
|
38
|
-
|
39
|
-
# Makes sure the log directory exists as long as we can write to it
|
40
|
-
def ensure_dir_exists
|
41
|
-
FileUtils.mkdir_p(File.dirname(log_path))
|
42
|
-
rescue Errno::EACCES
|
43
|
-
nil
|
35
|
+
.to(*[$stdout, file].compact)
|
44
36
|
end
|
45
37
|
|
46
38
|
# @return [Pathname] Path to a file to which we should log
|
@@ -51,7 +43,11 @@ module Karafka
|
|
51
43
|
# @return [File] file to which we want to write our logs
|
52
44
|
# @note File is being opened in append mode ('a')
|
53
45
|
def file
|
46
|
+
FileUtils.mkdir_p(File.dirname(log_path))
|
47
|
+
|
54
48
|
@file ||= File.open(log_path, 'a')
|
49
|
+
rescue Errno::EACCES, Errno::EROFS
|
50
|
+
nil
|
55
51
|
end
|
56
52
|
end
|
57
53
|
end
|
@@ -103,10 +103,10 @@ module Karafka
|
|
103
103
|
info "Responded from #{calling.class} using #{responder} with following data #{data}"
|
104
104
|
end
|
105
105
|
|
106
|
-
# Logs info that we're initializing Karafka
|
106
|
+
# Logs info that we're initializing Karafka framework components
|
107
107
|
# @param _event [Dry::Events::Event] event details including payload
|
108
108
|
def on_app_initializing(_event)
|
109
|
-
info "Initializing Karafka
|
109
|
+
info "Initializing Karafka framework #{::Process.pid}"
|
110
110
|
end
|
111
111
|
|
112
112
|
# Logs info that we're running Karafka app
|
@@ -8,9 +8,11 @@ module Karafka
|
|
8
8
|
class ConsumerGroup
|
9
9
|
extend Helpers::ConfigRetriever
|
10
10
|
|
11
|
-
attr_reader
|
12
|
-
|
13
|
-
|
11
|
+
attr_reader(
|
12
|
+
:topics,
|
13
|
+
:id,
|
14
|
+
:name
|
15
|
+
)
|
14
16
|
|
15
17
|
# @param name [String, Symbol] raw name of this consumer group. Raw means, that it does not
|
16
18
|
# yet have an application client_id namespace, this will be added here by default.
|
data/lib/karafka/server.rb
CHANGED
@@ -58,7 +58,7 @@ module Karafka
|
|
58
58
|
def stop_supervised
|
59
59
|
Karafka::App.stop!
|
60
60
|
|
61
|
-
#
|
61
|
+
# See https://github.com/dry-rb/dry-configurable/issues/93
|
62
62
|
timeout = Thread.new { Karafka::App.config.shutdown_timeout }.join.value
|
63
63
|
|
64
64
|
# We check from time to time (for the timeout period) if all the threads finished
|
data/lib/karafka/setup/config.rb
CHANGED
@@ -89,6 +89,9 @@ module Karafka
|
|
89
89
|
# are stored for further processing. Note, that each item in the queue represents a
|
90
90
|
# response from a single broker
|
91
91
|
setting :fetcher_max_queue_size, 10
|
92
|
+
# option assignment_strategy [Object] a strategy determining the assignment of
|
93
|
+
# partitions to the consumers.
|
94
|
+
setting :assignment_strategy, Karafka::AssignmentStrategies::RoundRobin.new
|
92
95
|
# option max_bytes_per_partition [Integer] the maximum amount of data fetched
|
93
96
|
# from a single partition at a time.
|
94
97
|
setting :max_bytes_per_partition, 1_048_576
|
@@ -54,7 +54,7 @@ class KarafkaApp < Karafka::App
|
|
54
54
|
# listen to only what you really need for given environment.
|
55
55
|
Karafka.monitor.subscribe(WaterDrop::Instrumentation::StdoutListener.new)
|
56
56
|
Karafka.monitor.subscribe(Karafka::Instrumentation::StdoutListener.new)
|
57
|
-
Karafka.monitor.subscribe(Karafka::Instrumentation::ProctitleListener.new)
|
57
|
+
# Karafka.monitor.subscribe(Karafka::Instrumentation::ProctitleListener.new)
|
58
58
|
|
59
59
|
# Uncomment that in order to achieve code reload in development mode
|
60
60
|
# Be aware, that this might have some side-effects. Please refer to the wiki
|
data/lib/karafka/version.rb
CHANGED
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: 1.4.
|
4
|
+
version: 1.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maciej Mensfeld
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
2DND//YJUikn1zwbz1kT70XmHd97B4Eytpln7K+M1u2g1pHVEPW4owD/ammXNpUy
|
37
37
|
nt70FcDD4yxJQ+0YNiHd0N8IcVBM1TMIVctMNQ==
|
38
38
|
-----END CERTIFICATE-----
|
39
|
-
date:
|
39
|
+
date: 2021-06-16 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: dry-configurable
|
@@ -122,20 +122,6 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '1.0'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: rake
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - ">="
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '11.3'
|
132
|
-
type: :runtime
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - ">="
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '11.3'
|
139
125
|
- !ruby/object:Gem::Dependency
|
140
126
|
name: ruby-kafka
|
141
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -227,6 +213,7 @@ files:
|
|
227
213
|
- karafka.gemspec
|
228
214
|
- lib/karafka.rb
|
229
215
|
- lib/karafka/app.rb
|
216
|
+
- lib/karafka/assignment_strategies/round_robin.rb
|
230
217
|
- lib/karafka/attributes_map.rb
|
231
218
|
- lib/karafka/backends/inline.rb
|
232
219
|
- lib/karafka/base_consumer.rb
|
@@ -237,6 +224,7 @@ files:
|
|
237
224
|
- lib/karafka/cli/flow.rb
|
238
225
|
- lib/karafka/cli/info.rb
|
239
226
|
- lib/karafka/cli/install.rb
|
227
|
+
- lib/karafka/cli/missingno.rb
|
240
228
|
- lib/karafka/cli/server.rb
|
241
229
|
- lib/karafka/code_reloader.rb
|
242
230
|
- lib/karafka/connection/api_adapter.rb
|
@@ -311,14 +299,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
311
299
|
requirements:
|
312
300
|
- - ">="
|
313
301
|
- !ruby/object:Gem::Version
|
314
|
-
version: 2.
|
302
|
+
version: 2.6.0
|
315
303
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
316
304
|
requirements:
|
317
305
|
- - ">="
|
318
306
|
- !ruby/object:Gem::Version
|
319
307
|
version: '0'
|
320
308
|
requirements: []
|
321
|
-
rubygems_version: 3.
|
309
|
+
rubygems_version: 3.2.20
|
322
310
|
signing_key:
|
323
311
|
specification_version: 4
|
324
312
|
summary: Ruby based framework for working with Apache Kafka
|
metadata.gz.sig
CHANGED
Binary file
|