karafka 1.4.0.rc1 → 1.4.3
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 -1
- data/.ruby-version +1 -1
- data/CHANGELOG.md +12 -2
- data/Gemfile.lock +56 -59
- data/README.md +7 -5
- data/config/errors.yml +2 -0
- 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 +3 -3
- data/lib/karafka/params/params.rb +4 -0
- 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/version.rb +1 -1
- metadata +7 -5
- 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: 0fae4fb99cb42515602d9f27a6d7a5bd7485e4e0b40868a6856766ebe7b50083
|
4
|
+
data.tar.gz: b82635f328ba711f836da733dd0ec5ed415446d3209918a20f7b6f42ff1e1ac2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f90e7c6757cd517649c0021f759db091c050899c8a7846d022fa58e117db61cb5a3f6ee640b452f43017e0b504b0ba6a3b075886b266438daf1098d0fa2bc48d
|
7
|
+
data.tar.gz: 7ab841ff7269992e90a17a88159baa9be67ab35866f8d174a434bd6efbecceb1521bbf142b6c9ebb37cabbea8a125e49b60fde3844b2a0e6ce3b62ef941b6a75
|
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,17 @@ 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
20
|
- '2.5'
|
18
21
|
include:
|
19
|
-
- ruby: '
|
22
|
+
- ruby: '3.0'
|
20
23
|
coverage: 'true'
|
21
24
|
steps:
|
22
25
|
- uses: actions/checkout@v2
|
@@ -40,6 +43,26 @@ jobs:
|
|
40
43
|
env:
|
41
44
|
GITHUB_COVERAGE: ${{matrix.coverage}}
|
42
45
|
run: bundle exec rspec
|
46
|
+
|
47
|
+
diffend:
|
48
|
+
runs-on: ubuntu-latest
|
49
|
+
strategy:
|
50
|
+
fail-fast: false
|
51
|
+
steps:
|
52
|
+
- uses: actions/checkout@v2
|
53
|
+
with:
|
54
|
+
fetch-depth: 0
|
55
|
+
- name: Set up Ruby
|
56
|
+
uses: ruby/setup-ruby@v1
|
57
|
+
with:
|
58
|
+
ruby-version: 3.0
|
59
|
+
- name: Install latest bundler
|
60
|
+
run: gem install bundler --no-document
|
61
|
+
- name: Install Diffend plugin
|
62
|
+
run: bundle plugin install diffend
|
63
|
+
- name: Bundle Secure
|
64
|
+
run: bundle secure
|
65
|
+
|
43
66
|
coditsu:
|
44
67
|
runs-on: ubuntu-latest
|
45
68
|
strategy:
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.0.0
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,19 @@
|
|
1
1
|
# Karafka framework changelog
|
2
2
|
|
3
|
-
## 1.4.
|
3
|
+
## 1.4.3 (2021-03-24)
|
4
|
+
- Fixes for Ruby 3.0 compatibility
|
5
|
+
|
6
|
+
## 1.4.2 (2021-02-16)
|
7
|
+
- Rescue Errno::EROFS in ensure_dir_exists (unasuke)
|
8
|
+
|
9
|
+
## 1.4.1 (2020-12-04)
|
10
|
+
- Return non-zero exit code when printing usage
|
11
|
+
- Add support for :assignment_strategy for consumers
|
12
|
+
|
13
|
+
## 1.4.0 (2020-09-05)
|
4
14
|
- Rename `Karafka::Params::Metadata` to `Karafka::Params::BatchMetadata`
|
5
15
|
` Rename consumer `#metadata` to `#batch_metadata`
|
6
|
-
- Separate metadata (including Karafka native metadata) from the root of params
|
16
|
+
- Separate metadata (including Karafka native metadata) from the root of params (backwards compatibility preserved thanks to rabotyaga)
|
7
17
|
- Remove metadata hash dependency
|
8
18
|
- Remove params dependency on a hash in favour of PORO
|
9
19
|
- Remove batch metadata dependency on a hash
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
karafka (1.4.
|
4
|
+
karafka (1.4.3)
|
5
5
|
dry-configurable (~> 0.8)
|
6
6
|
dry-inflector (~> 0.1)
|
7
7
|
dry-monitor (~> 0.3)
|
@@ -17,29 +17,28 @@ PATH
|
|
17
17
|
GEM
|
18
18
|
remote: https://rubygems.org/
|
19
19
|
specs:
|
20
|
-
activesupport (6.
|
20
|
+
activesupport (6.1.3)
|
21
21
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
22
|
-
i18n (>=
|
23
|
-
minitest (
|
24
|
-
tzinfo (~>
|
25
|
-
zeitwerk (~> 2.
|
22
|
+
i18n (>= 1.6, < 2)
|
23
|
+
minitest (>= 5.1)
|
24
|
+
tzinfo (~> 2.0)
|
25
|
+
zeitwerk (~> 2.3)
|
26
26
|
byebug (11.1.3)
|
27
|
-
concurrent-ruby (1.1.
|
28
|
-
delivery_boy (1.0
|
29
|
-
king_konf (~> 0
|
27
|
+
concurrent-ruby (1.1.8)
|
28
|
+
delivery_boy (1.1.0)
|
29
|
+
king_konf (~> 1.0)
|
30
30
|
ruby-kafka (~> 1.0)
|
31
31
|
diff-lcs (1.4.4)
|
32
|
-
digest-crc (0.6.
|
33
|
-
rake (
|
34
|
-
docile (1.3.
|
35
|
-
dry-configurable (0.
|
32
|
+
digest-crc (0.6.3)
|
33
|
+
rake (>= 12.0.0, < 14.0.0)
|
34
|
+
docile (1.3.5)
|
35
|
+
dry-configurable (0.12.1)
|
36
36
|
concurrent-ruby (~> 1.0)
|
37
|
-
dry-core (~> 0.
|
38
|
-
dry-equalizer (~> 0.2)
|
37
|
+
dry-core (~> 0.5, >= 0.5.0)
|
39
38
|
dry-container (0.7.2)
|
40
39
|
concurrent-ruby (~> 1.0)
|
41
40
|
dry-configurable (~> 0.1, >= 0.1.3)
|
42
|
-
dry-core (0.
|
41
|
+
dry-core (0.5.0)
|
43
42
|
concurrent-ruby (~> 1.0)
|
44
43
|
dry-equalizer (0.3.0)
|
45
44
|
dry-events (0.2.0)
|
@@ -47,86 +46,84 @@ GEM
|
|
47
46
|
dry-core (~> 0.4)
|
48
47
|
dry-equalizer (~> 0.2)
|
49
48
|
dry-inflector (0.2.0)
|
50
|
-
dry-initializer (3.0.
|
51
|
-
dry-logic (1.0
|
49
|
+
dry-initializer (3.0.4)
|
50
|
+
dry-logic (1.1.0)
|
52
51
|
concurrent-ruby (~> 1.0)
|
53
|
-
dry-core (~> 0.
|
54
|
-
dry-equalizer (~> 0.2)
|
52
|
+
dry-core (~> 0.5, >= 0.5)
|
55
53
|
dry-monitor (0.3.2)
|
56
54
|
dry-configurable (~> 0.5)
|
57
55
|
dry-core (~> 0.4)
|
58
56
|
dry-equalizer (~> 0.2)
|
59
57
|
dry-events (~> 0.2)
|
60
|
-
dry-schema (1.
|
58
|
+
dry-schema (1.6.1)
|
61
59
|
concurrent-ruby (~> 1.0)
|
62
60
|
dry-configurable (~> 0.8, >= 0.8.3)
|
63
|
-
dry-core (~> 0.
|
64
|
-
dry-equalizer (~> 0.2)
|
61
|
+
dry-core (~> 0.5, >= 0.5)
|
65
62
|
dry-initializer (~> 3.0)
|
66
63
|
dry-logic (~> 1.0)
|
67
|
-
dry-types (~> 1.
|
68
|
-
dry-types (1.
|
64
|
+
dry-types (~> 1.5)
|
65
|
+
dry-types (1.5.1)
|
69
66
|
concurrent-ruby (~> 1.0)
|
70
67
|
dry-container (~> 0.3)
|
71
|
-
dry-core (~> 0.
|
72
|
-
dry-equalizer (~> 0.3)
|
68
|
+
dry-core (~> 0.5, >= 0.5)
|
73
69
|
dry-inflector (~> 0.1, >= 0.1.2)
|
74
70
|
dry-logic (~> 1.0, >= 1.0.2)
|
75
|
-
dry-validation (1.
|
71
|
+
dry-validation (1.6.0)
|
76
72
|
concurrent-ruby (~> 1.0)
|
77
73
|
dry-container (~> 0.7, >= 0.7.1)
|
78
74
|
dry-core (~> 0.4)
|
79
75
|
dry-equalizer (~> 0.2)
|
80
76
|
dry-initializer (~> 3.0)
|
81
|
-
dry-schema (~> 1.5)
|
77
|
+
dry-schema (~> 1.5, >= 1.5.2)
|
82
78
|
envlogic (1.1.2)
|
83
79
|
dry-inflector (~> 0.1)
|
84
80
|
factory_bot (6.1.0)
|
85
81
|
activesupport (>= 5.0.0)
|
86
|
-
i18n (1.8.
|
82
|
+
i18n (1.8.9)
|
87
83
|
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.
|
84
|
+
io-console (0.5.9)
|
85
|
+
irb (1.3.4)
|
86
|
+
reline (>= 0.1.5)
|
87
|
+
king_konf (1.0.0)
|
88
|
+
minitest (5.14.4)
|
89
|
+
rake (13.0.3)
|
90
|
+
reline (0.2.4)
|
95
91
|
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.
|
92
|
+
rspec (3.10.0)
|
93
|
+
rspec-core (~> 3.10.0)
|
94
|
+
rspec-expectations (~> 3.10.0)
|
95
|
+
rspec-mocks (~> 3.10.0)
|
96
|
+
rspec-core (3.10.1)
|
97
|
+
rspec-support (~> 3.10.0)
|
98
|
+
rspec-expectations (3.10.1)
|
103
99
|
diff-lcs (>= 1.2.0, < 2.0)
|
104
|
-
rspec-support (~> 3.
|
105
|
-
rspec-mocks (3.
|
100
|
+
rspec-support (~> 3.10.0)
|
101
|
+
rspec-mocks (3.10.2)
|
106
102
|
diff-lcs (>= 1.2.0, < 2.0)
|
107
|
-
rspec-support (~> 3.
|
108
|
-
rspec-support (3.
|
109
|
-
ruby-kafka (1.
|
103
|
+
rspec-support (~> 3.10.0)
|
104
|
+
rspec-support (3.10.2)
|
105
|
+
ruby-kafka (1.3.0)
|
110
106
|
digest-crc
|
111
|
-
simplecov (0.
|
107
|
+
simplecov (0.21.2)
|
112
108
|
docile (~> 1.1)
|
113
109
|
simplecov-html (~> 0.11)
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
110
|
+
simplecov_json_formatter (~> 0.1)
|
111
|
+
simplecov-html (0.12.3)
|
112
|
+
simplecov_json_formatter (0.1.2)
|
113
|
+
thor (1.1.0)
|
114
|
+
tzinfo (2.0.4)
|
115
|
+
concurrent-ruby (~> 1.0)
|
116
|
+
waterdrop (1.4.1)
|
120
117
|
delivery_boy (>= 0.2, < 2.x)
|
121
118
|
dry-configurable (~> 0.8)
|
122
119
|
dry-monitor (~> 0.3)
|
123
120
|
dry-validation (~> 1.2)
|
124
121
|
ruby-kafka (>= 0.7.8)
|
125
122
|
zeitwerk (~> 2.1)
|
126
|
-
zeitwerk (2.4.
|
123
|
+
zeitwerk (2.4.2)
|
127
124
|
|
128
125
|
PLATFORMS
|
129
|
-
|
126
|
+
x86_64-linux
|
130
127
|
|
131
128
|
DEPENDENCIES
|
132
129
|
byebug
|
@@ -136,4 +133,4 @@ DEPENDENCIES
|
|
136
133
|
simplecov
|
137
134
|
|
138
135
|
BUNDLED WITH
|
139
|
-
2.
|
136
|
+
2.2.15
|
data/README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
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
|
-
|
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
|
+
..
|
9
|
+
Documentation presented here refers to Karafka `1.4`.
|
8
10
|
|
9
11
|
## About Karafka
|
10
12
|
|
@@ -72,7 +74,7 @@ Karafka framework and Karafka team are __not__ related to Kafka streaming servic
|
|
72
74
|
## References
|
73
75
|
|
74
76
|
* [Karafka framework](https://github.com/karafka/karafka)
|
75
|
-
* [Karafka
|
77
|
+
* [Karafka GitHub Actions](https://github.com/karafka/karafka/actions)
|
76
78
|
* [Karafka Coditsu](https://app.coditsu.io/karafka/repositories/karafka)
|
77
79
|
|
78
80
|
## Note on contributions
|
data/config/errors.yml
CHANGED
@@ -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
|
|
@@ -29,17 +29,17 @@ module Karafka
|
|
29
29
|
|
30
30
|
# @return [Karafka::Helpers::MultiDelegator] multi delegator instance
|
31
31
|
# to which we will be writing logs
|
32
|
-
# We use this approach to log stuff to file and to the
|
32
|
+
# We use this approach to log stuff to file and to the $stdout at the same time
|
33
33
|
def target
|
34
34
|
Karafka::Helpers::MultiDelegator
|
35
35
|
.delegate(:write, :close)
|
36
|
-
.to(
|
36
|
+
.to($stdout, file)
|
37
37
|
end
|
38
38
|
|
39
39
|
# Makes sure the log directory exists as long as we can write to it
|
40
40
|
def ensure_dir_exists
|
41
41
|
FileUtils.mkdir_p(File.dirname(log_path))
|
42
|
-
rescue Errno::EACCES
|
42
|
+
rescue Errno::EACCES, Errno::EROFS
|
43
43
|
nil
|
44
44
|
end
|
45
45
|
|
@@ -7,8 +7,12 @@ module Karafka
|
|
7
7
|
# using deserializer until we execute our logic. That way we can operate with
|
8
8
|
# heavy-deserialization data without slowing down the whole application.
|
9
9
|
class Params
|
10
|
+
extend Forwardable
|
11
|
+
|
10
12
|
attr_reader :raw_payload, :metadata
|
11
13
|
|
14
|
+
def_delegators :metadata, *Metadata.members
|
15
|
+
|
12
16
|
# @param raw_payload [Object] incoming payload before deserialization
|
13
17
|
# @param metadata [Karafka::Params::Metadata] message metadata object
|
14
18
|
def initialize(raw_payload, metadata)
|
@@ -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
|
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.3
|
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-03-24 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: dry-configurable
|
@@ -227,6 +227,7 @@ files:
|
|
227
227
|
- karafka.gemspec
|
228
228
|
- lib/karafka.rb
|
229
229
|
- lib/karafka/app.rb
|
230
|
+
- lib/karafka/assignment_strategies/round_robin.rb
|
230
231
|
- lib/karafka/attributes_map.rb
|
231
232
|
- lib/karafka/backends/inline.rb
|
232
233
|
- lib/karafka/base_consumer.rb
|
@@ -237,6 +238,7 @@ files:
|
|
237
238
|
- lib/karafka/cli/flow.rb
|
238
239
|
- lib/karafka/cli/info.rb
|
239
240
|
- lib/karafka/cli/install.rb
|
241
|
+
- lib/karafka/cli/missingno.rb
|
240
242
|
- lib/karafka/cli/server.rb
|
241
243
|
- lib/karafka/code_reloader.rb
|
242
244
|
- lib/karafka/connection/api_adapter.rb
|
@@ -314,11 +316,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
314
316
|
version: 2.5.0
|
315
317
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
316
318
|
requirements:
|
317
|
-
- - "
|
319
|
+
- - ">="
|
318
320
|
- !ruby/object:Gem::Version
|
319
|
-
version:
|
321
|
+
version: '0'
|
320
322
|
requirements: []
|
321
|
-
rubygems_version: 3.
|
323
|
+
rubygems_version: 3.2.3
|
322
324
|
signing_key:
|
323
325
|
specification_version: 4
|
324
326
|
summary: Ruby based framework for working with Apache Kafka
|
metadata.gz.sig
CHANGED
Binary file
|