karafka 1.3.6 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.diffend.yml +3 -0
  5. data/.github/workflows/ci.yml +52 -0
  6. data/.ruby-version +1 -1
  7. data/CHANGELOG.md +27 -1
  8. data/CODE_OF_CONDUCT.md +1 -1
  9. data/Gemfile +2 -0
  10. data/Gemfile.lock +42 -41
  11. data/README.md +3 -5
  12. data/certs/mensfeld.pem +21 -21
  13. data/config/errors.yml +2 -0
  14. data/docker-compose.yml +17 -0
  15. data/karafka.gemspec +3 -4
  16. data/lib/karafka.rb +1 -1
  17. data/lib/karafka/assignment_strategies/round_robin.rb +13 -0
  18. data/lib/karafka/attributes_map.rb +1 -0
  19. data/lib/karafka/cli.rb +8 -0
  20. data/lib/karafka/cli/base.rb +4 -4
  21. data/lib/karafka/cli/missingno.rb +19 -0
  22. data/lib/karafka/connection/api_adapter.rb +5 -3
  23. data/lib/karafka/connection/batch_delegator.rb +5 -1
  24. data/lib/karafka/consumers/batch_metadata.rb +10 -0
  25. data/lib/karafka/consumers/includer.rb +5 -4
  26. data/lib/karafka/contracts.rb +1 -1
  27. data/lib/karafka/contracts/consumer_group.rb +8 -3
  28. data/lib/karafka/helpers/class_matcher.rb +1 -1
  29. data/lib/karafka/instrumentation/logger.rb +2 -2
  30. data/lib/karafka/instrumentation/stdout_listener.rb +4 -2
  31. data/lib/karafka/params/batch_metadata.rb +26 -0
  32. data/lib/karafka/params/builders/batch_metadata.rb +30 -0
  33. data/lib/karafka/params/builders/params.rb +17 -15
  34. data/lib/karafka/params/builders/params_batch.rb +2 -2
  35. data/lib/karafka/params/metadata.rb +14 -29
  36. data/lib/karafka/params/params.rb +27 -41
  37. data/lib/karafka/params/params_batch.rb +15 -16
  38. data/lib/karafka/routing/builder.rb +1 -0
  39. data/lib/karafka/routing/consumer_group.rb +5 -3
  40. data/lib/karafka/serialization/json/deserializer.rb +2 -2
  41. data/lib/karafka/setup/config.rb +5 -0
  42. data/lib/karafka/version.rb +1 -1
  43. metadata +37 -46
  44. metadata.gz.sig +0 -0
  45. data/.travis.yml +0 -36
  46. data/lib/karafka/consumers/metadata.rb +0 -10
  47. data/lib/karafka/params/builders/metadata.rb +0 -33
@@ -15,47 +15,46 @@ module Karafka
15
15
  @params_array = params_array
16
16
  end
17
17
 
18
- # @yieldparam [Karafka::Params::Params] each deserialized and loaded params instance
19
- # @note Invocation of this method will cause loading and deserializing each param after
20
- # another. If you want to get access without deserializing, please access params_array
21
- # directly
18
+ # @yieldparam [Karafka::Params::Params] each params instance
19
+ # @note Invocation of this method will not cause loading and deserializing each param after
20
+ # another.
22
21
  def each
23
- @params_array.each { |param| yield(param.deserialize!) }
22
+ @params_array.each { |param| yield(param) }
24
23
  end
25
24
 
26
25
  # @return [Array<Karafka::Params::Params>] returns all the params in a loaded state, so they
27
26
  # can be used for batch insert, etc. Without invoking all, up until first use, they won't
28
27
  # be deserialized
29
28
  def deserialize!
30
- each(&:itself)
29
+ each(&:payload)
31
30
  end
32
31
 
33
32
  # @return [Array<Object>] array with deserialized payloads. This method can be useful when
34
33
  # we don't care about metadata and just want to extract all the data payloads from the
35
34
  # batch
36
35
  def payloads
37
- deserialize!.map(&:payload)
36
+ map(&:payload)
38
37
  end
39
38
 
40
- # @return [Karafka::Params::Params] first element after the deserialization process
39
+ # @return [Karafka::Params::Params] first element
41
40
  def first
42
- @params_array.first.deserialize!
41
+ @params_array.first
43
42
  end
44
43
 
45
- # @return [Karafka::Params::Params] last element after the deserialization process
44
+ # @return [Karafka::Params::Params] last element
46
45
  def last
47
- @params_array.last.deserialize!
48
- end
49
-
50
- # @return [Array<Karafka::Params::Params>] pure array with params (not deserialized)
51
- def to_a
52
- @params_array
46
+ @params_array.last
53
47
  end
54
48
 
55
49
  # @return [Integer] number of messages in the batch
56
50
  def size
57
51
  @params_array.size
58
52
  end
53
+
54
+ # @return [Array<Karafka::Params::Params>] pure array with params
55
+ def to_a
56
+ @params_array
57
+ end
59
58
  end
60
59
  end
61
60
  end
@@ -16,6 +16,7 @@ module Karafka
16
16
  private_constant :CONTRACT
17
17
 
18
18
  def initialize
19
+ super
19
20
  @draws = Concurrent::Array.new
20
21
  end
21
22
 
@@ -8,9 +8,11 @@ module Karafka
8
8
  class ConsumerGroup
9
9
  extend Helpers::ConfigRetriever
10
10
 
11
- attr_reader :topics
12
- attr_reader :id
13
- attr_reader :name
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.
@@ -17,8 +17,8 @@ module Karafka
17
17
  # }
18
18
  # Deserializer.call(params) #=> { 'a' => 1 }
19
19
  def call(params)
20
- ::MultiJson.load(params['payload'])
21
- rescue ::MultiJson::ParseError => e
20
+ params.raw_payload.nil? ? nil : ::JSON.parse(params.raw_payload)
21
+ rescue ::JSON::ParserError => e
22
22
  raise ::Karafka::Errors::DeserializationError, e
23
23
  end
24
24
  end
@@ -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
@@ -124,6 +127,8 @@ module Karafka
124
127
  # will be killed. Note that some Kafka operations are by definition long-running, such as
125
128
  # waiting for new messages to arrive in a partition, so don't set this value too low
126
129
  setting :socket_timeout, 30
130
+ # option partitioner [Object, nil] the partitioner that should be used by the client
131
+ setting :partitioner, nil
127
132
 
128
133
  # SSL authentication related settings
129
134
  # option ca_cert [String, nil] SSL CA certificate
@@ -3,5 +3,5 @@
3
3
  # Main module namespace
4
4
  module Karafka
5
5
  # Current Karafka version
6
- VERSION = '1.3.6'
6
+ VERSION = '1.4.1'
7
7
  end
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.3.6
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Mensfeld
@@ -13,30 +13,30 @@ cert_chain:
13
13
  - |
14
14
  -----BEGIN CERTIFICATE-----
15
15
  MIIEODCCAqCgAwIBAgIBATANBgkqhkiG9w0BAQsFADAjMSEwHwYDVQQDDBhtYWNp
16
- ZWovREM9bWVuc2ZlbGQvREM9cGwwHhcNMTkwNzMwMTQ1NDU0WhcNMjAwNzI5MTQ1
17
- NDU0WjAjMSEwHwYDVQQDDBhtYWNpZWovREM9bWVuc2ZlbGQvREM9cGwwggGiMA0G
18
- CSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQC9fCwtaHZG2SyyNXiH8r0QbJQx/xxl
19
- dkvwWz9QGJO+O8rEx20FB1Ab+MVkfOscwIv5jWpmk1U9whzDPl1uFtIbgu+sk+Zb
20
- uQlZyK/DPN6c+/BbBL+RryTBRyvkPLoCVwm7uxc/JZ1n4AI6eF4cCZ2ieZ9QgQbU
21
- MQs2QPqs9hT50Ez/40GnOdadVfiDDGz+NME2C4ms0BriXwZ1tcRTfJIHe2xjIbbb
22
- y5qRGfsLKcgMzvLQR24olixyX1MR0s4+Wveq3QL/gBhL4veUcv+UABJA8IJR0kyB
23
- seHHutusiwZ1v3SjjjW1xLLrc2ARV0mgCb0WaK2T4iA3oFTGLh6Ydz8LNl31KQFv
24
- 94nRd8IhmJxrhQ6dQ/WT9IXoa5S9lfT5lPJeINemH4/6QPABzf9W2IZlCdI9wCdB
25
- TBaw57MKneGAYZiKjw6OALSy2ltQUCl3RqFl3VP7n8uFy1U987Q5VIIQ3O1UUsQD
26
- Oe/h+r7GUU4R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u2g1pHVEPW4owD/ammXNpUy
37
+ nt70FcDD4yxJQ+0YNiHd0N8IcVBM1TMIVctMNQ==
38
38
  -----END CERTIFICATE-----
39
- date: 2020-04-24 00:00:00.000000000 Z
39
+ date: 2020-12-04 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: multi_json
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '1.12'
132
- type: :runtime
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '1.12'
139
125
  - !ruby/object:Gem::Dependency
140
126
  name: rake
141
127
  requirement: !ruby/object:Gem::Requirement
@@ -156,14 +142,14 @@ dependencies:
156
142
  requirements:
157
143
  - - ">="
158
144
  - !ruby/object:Gem::Version
159
- version: 0.7.8
145
+ version: 1.0.0
160
146
  type: :runtime
161
147
  prerelease: false
162
148
  version_requirements: !ruby/object:Gem::Requirement
163
149
  requirements:
164
150
  - - ">="
165
151
  - !ruby/object:Gem::Version
166
- version: 0.7.8
152
+ version: 1.0.0
167
153
  - !ruby/object:Gem::Dependency
168
154
  name: thor
169
155
  requirement: !ruby/object:Gem::Requirement
@@ -184,14 +170,14 @@ dependencies:
184
170
  requirements:
185
171
  - - "~>"
186
172
  - !ruby/object:Gem::Version
187
- version: 1.3.0
173
+ version: 1.4.0
188
174
  type: :runtime
189
175
  prerelease: false
190
176
  version_requirements: !ruby/object:Gem::Requirement
191
177
  requirements:
192
178
  - - "~>"
193
179
  - !ruby/object:Gem::Version
194
- version: 1.3.0
180
+ version: 1.4.0
195
181
  - !ruby/object:Gem::Dependency
196
182
  name: zeitwerk
197
183
  requirement: !ruby/object:Gem::Requirement
@@ -208,7 +194,7 @@ dependencies:
208
194
  version: '2.1'
209
195
  description: Framework used to simplify Apache Kafka based Ruby applications development
210
196
  email:
211
- - maciej@coditsu.io
197
+ - maciej@mensfeld.pl
212
198
  - pavlo.vavruk@gmail.com
213
199
  - adam99g@gmail.com
214
200
  executables:
@@ -218,14 +204,15 @@ extra_rdoc_files: []
218
204
  files:
219
205
  - ".coditsu/ci.yml"
220
206
  - ".console_irbrc"
207
+ - ".diffend.yml"
221
208
  - ".github/FUNDING.yml"
222
209
  - ".github/ISSUE_TEMPLATE/bug_report.md"
223
210
  - ".github/ISSUE_TEMPLATE/feature_request.md"
211
+ - ".github/workflows/ci.yml"
224
212
  - ".gitignore"
225
213
  - ".rspec"
226
214
  - ".ruby-gemset"
227
215
  - ".ruby-version"
228
- - ".travis.yml"
229
216
  - CHANGELOG.md
230
217
  - CODE_OF_CONDUCT.md
231
218
  - CONTRIBUTING.md
@@ -236,9 +223,11 @@ files:
236
223
  - bin/karafka
237
224
  - certs/mensfeld.pem
238
225
  - config/errors.yml
226
+ - docker-compose.yml
239
227
  - karafka.gemspec
240
228
  - lib/karafka.rb
241
229
  - lib/karafka/app.rb
230
+ - lib/karafka/assignment_strategies/round_robin.rb
242
231
  - lib/karafka/attributes_map.rb
243
232
  - lib/karafka/backends/inline.rb
244
233
  - lib/karafka/base_consumer.rb
@@ -249,6 +238,7 @@ files:
249
238
  - lib/karafka/cli/flow.rb
250
239
  - lib/karafka/cli/info.rb
251
240
  - lib/karafka/cli/install.rb
241
+ - lib/karafka/cli/missingno.rb
252
242
  - lib/karafka/cli/server.rb
253
243
  - lib/karafka/code_reloader.rb
254
244
  - lib/karafka/connection/api_adapter.rb
@@ -257,9 +247,9 @@ files:
257
247
  - lib/karafka/connection/client.rb
258
248
  - lib/karafka/connection/listener.rb
259
249
  - lib/karafka/connection/message_delegator.rb
250
+ - lib/karafka/consumers/batch_metadata.rb
260
251
  - lib/karafka/consumers/callbacks.rb
261
252
  - lib/karafka/consumers/includer.rb
262
- - lib/karafka/consumers/metadata.rb
263
253
  - lib/karafka/consumers/responders.rb
264
254
  - lib/karafka/consumers/single_params.rb
265
255
  - lib/karafka/contracts.rb
@@ -278,7 +268,8 @@ files:
278
268
  - lib/karafka/instrumentation/monitor.rb
279
269
  - lib/karafka/instrumentation/proctitle_listener.rb
280
270
  - lib/karafka/instrumentation/stdout_listener.rb
281
- - lib/karafka/params/builders/metadata.rb
271
+ - lib/karafka/params/batch_metadata.rb
272
+ - lib/karafka/params/builders/batch_metadata.rb
282
273
  - lib/karafka/params/builders/params.rb
283
274
  - lib/karafka/params/builders/params_batch.rb
284
275
  - lib/karafka/params/metadata.rb
@@ -329,7 +320,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
329
320
  - !ruby/object:Gem::Version
330
321
  version: '0'
331
322
  requirements: []
332
- rubygems_version: 3.1.2
323
+ rubygems_version: 3.1.4
333
324
  signing_key:
334
325
  specification_version: 4
335
326
  summary: Ruby based framework for working with Apache Kafka
metadata.gz.sig CHANGED
Binary file
@@ -1,36 +0,0 @@
1
- services:
2
- - docker
3
-
4
- dist: trusty
5
- sudo: false
6
- cache: bundler
7
-
8
- git:
9
- depth: false
10
-
11
- test: &test
12
- stage: Test
13
- language: ruby
14
- before_install:
15
- - yes | gem update --system
16
- script: bundle exec rspec
17
-
18
- jobs:
19
- include:
20
- - <<: *test
21
- rvm: 2.7.1
22
- - <<: *test
23
- rvm: 2.6.6
24
- - <<: *test
25
- rvm: 2.5.8
26
-
27
- - stage: coditsu
28
- language: ruby
29
- rvm: 2.7.1
30
- before_install:
31
- - yes | gem update --system
32
- script: \curl -sSL https://api.coditsu.io/run/ci | bash
33
-
34
- stages:
35
- - test
36
- - coditsu
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Karafka
4
- module Consumers
5
- # Brings the metadata into consumers that support batch_fetching
6
- module Metadata
7
- attr_accessor :metadata
8
- end
9
- end
10
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Karafka
4
- module Params
5
- module Builders
6
- # Builder for creating metadata object based on the message or batch informations
7
- # @note We have 2 ways of creating metadata based on the way ruby-kafka operates
8
- module Metadata
9
- class << self
10
- # Creates metadata based on the kafka batch data
11
- # @param kafka_batch [Kafka::FetchedBatch] kafka batch details
12
- # @param topic [Karafka::Routing::Topic] topic for which we've fetched the batch
13
- # @return [Karafka::Params::Metadata] metadata object
14
- def from_kafka_batch(kafka_batch, topic)
15
- Karafka::Params::Metadata
16
- .new
17
- .merge!(
18
- 'batch_size' => kafka_batch.messages.count,
19
- 'first_offset' => kafka_batch.first_offset,
20
- 'highwater_mark_offset' => kafka_batch.highwater_mark_offset,
21
- 'last_offset' => kafka_batch.last_offset,
22
- 'offset_lag' => kafka_batch.offset_lag,
23
- 'deserializer' => topic.deserializer,
24
- 'partition' => kafka_batch.partition,
25
- 'topic' => kafka_batch.topic,
26
- 'unknown_last_offset' => kafka_batch.unknown_last_offset?
27
- )
28
- end
29
- end
30
- end
31
- end
32
- end
33
- end