racecar 0.4.2 → 0.5.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +35 -2
- data/lib/racecar/config.rb +1 -1
- data/lib/racecar/consumer.rb +6 -1
- data/lib/racecar/runner.rb +5 -3
- data/lib/racecar/version.rb +1 -1
- data/racecar.gemspec +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5806641d4fcbd87d7625458de4ed60b19db3b4a8695d52dc062c72e1db281136
|
4
|
+
data.tar.gz: '08f9d6c439bcbc97bc05bcffb37d97b6eaf3b0a375deb85d1ad33dd2c004c9f7'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18b8f848e4830f538b679cb3301f9bdcff36f0ccf4a4dfd0b7edc125aaa4a738164dd879d10366878ca3b74876506471809880d5ce23a607e22c8fcf0de1768d
|
7
|
+
data.tar.gz: 32af67f7bafd1320423e60f18895e2264c8fe623a1ff3ef96d457255c286a795dcee35ed83e1dd6b581baa14f9defc889757daedaf516623f46e7a7273d98a10
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -147,6 +147,32 @@ end
|
|
147
147
|
|
148
148
|
An important detail is that, if an exception is raised while processing a batch, the _whole batch_ is re-processed.
|
149
149
|
|
150
|
+
#### Message headers
|
151
|
+
|
152
|
+
Any headers set on the message will be available when consuming the message:
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
message.headers #=> { "Header-A" => 42, ... }
|
156
|
+
```
|
157
|
+
|
158
|
+
#### Heartbeats
|
159
|
+
|
160
|
+
In order to avoid your consumer being kicked out of its group during long-running message processing operations, it may be a good idea to periodically send so-called _heartbeats_ back to Kafka. This is done automatically for you after each message has been processed, but if the processing of a _single_ message takes a long time you may run into group stability issues.
|
161
|
+
|
162
|
+
If possible, intersperse `heartbeat` calls in between long-running operations in your consumer, e.g.
|
163
|
+
|
164
|
+
```ruby
|
165
|
+
def process(message)
|
166
|
+
long_running_op_one(message)
|
167
|
+
|
168
|
+
# Signals back to Kafka that we're still alive!
|
169
|
+
heartbeat
|
170
|
+
|
171
|
+
long_running_op_two(message)
|
172
|
+
end
|
173
|
+
```
|
174
|
+
|
175
|
+
|
150
176
|
#### Tearing down resources when stopping
|
151
177
|
|
152
178
|
When a Racecar consumer shuts down, it gets the opportunity to tear down any resources held by the consumer instance. For example, it may make sense to close any open files or network connections. Doing so is simple: just implement a `#teardown` method in your consumer class and it will be called during the shutdown procedure.
|
@@ -203,6 +229,8 @@ class GeoCodingConsumer < Racecar::Consumer
|
|
203
229
|
end
|
204
230
|
```
|
205
231
|
|
232
|
+
You can set message headers by passing a `headers:` option with a Hash of headers.
|
233
|
+
|
206
234
|
### Configuration
|
207
235
|
|
208
236
|
Racecar provides a flexible way to configure your consumer in a way that feels at home in a Rails application. If you haven't already, run `bundle exec rails generate racecar:install` in order to generate a config file. You'll get a separate section for each Rails environment, with the common configuration values in a shared `common` section.
|
@@ -227,6 +255,11 @@ end
|
|
227
255
|
* `group_id` – The group id to use for a given group of consumers. Note that this _must_ be different for each consumer class. If left blank a group id is generated based on the consumer class name.
|
228
256
|
* `group_id_prefix` – A prefix used when generating consumer group names. For instance, if you set the prefix to be `kevin.` and your consumer class is named `BaconConsumer`, the resulting consumer group will be named `kevin.bacon_consumer`.
|
229
257
|
|
258
|
+
#### Logging
|
259
|
+
|
260
|
+
* `logfile` – A filename that log messages should be written to. Default is `nil`, which means logs will be written to standard output.
|
261
|
+
* `log_level` – The log level for the Racecar logs, one of `debug`, `info`, `warn`, or `error`. Default is `info`.
|
262
|
+
|
230
263
|
#### Consumer checkpointing
|
231
264
|
|
232
265
|
The consumers will checkpoint their positions from time to time in order to be able to recover from failures. This is called _committing offsets_, since it's done by tracking the offset reached in each partition being processed, and committing those offset numbers to the Kafka offset storage API. If you can tolerate more double-processing after a failure, you can increase the interval between commits in order to better performance. You can also do the opposite if you prefer less chance of double-processing.
|
@@ -253,7 +286,7 @@ Kafka is _really_ good at throwing data at consumers, so you may want to tune th
|
|
253
286
|
Racecar uses ruby-kafka under the hood, which fetches messages from the Kafka brokers in a background thread. This thread pushes fetch responses, possible containing messages from many partitions, into a queue that is read by the processing thread (AKA your code). The main way to control the fetcher thread is to control the size of those responses and the size of the queue.
|
254
287
|
|
255
288
|
* `max_bytes` — The maximum size of message sets returned from a single fetch request.
|
256
|
-
* `max_fetch_queue_size` — The maximum number of fetch responses to keep in the queue.
|
289
|
+
* `max_fetch_queue_size` — The maximum number of fetch responses to keep in the queue. Once reached, the fetcher will back off until the queue gets back down under to limit.
|
257
290
|
|
258
291
|
The memory usage limit is roughly estimated as `max_bytes * max_fetch_queue_size`, plus whatever your application uses.
|
259
292
|
|
@@ -372,7 +405,7 @@ Again, the recommended approach is to manage the processes using process manager
|
|
372
405
|
|
373
406
|
### Handling errors
|
374
407
|
|
375
|
-
When processing messages from a Kafka topic, your code may encounter an error and raise an exception. The cause is typically
|
408
|
+
When processing messages from a Kafka topic, your code may encounter an error and raise an exception. The cause is typically one of two things:
|
376
409
|
|
377
410
|
1. The message being processed is somehow malformed or doesn't conform with the assumptions made by the processing code.
|
378
411
|
2. You're using some external resource such as a database or a network API that is temporarily unavailable.
|
data/lib/racecar/config.rb
CHANGED
data/lib/racecar/consumer.rb
CHANGED
@@ -28,7 +28,8 @@ module Racecar
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
def configure(producer:)
|
31
|
+
def configure(consumer:, producer:)
|
32
|
+
@_consumer = consumer
|
32
33
|
@_producer = producer
|
33
34
|
end
|
34
35
|
|
@@ -36,6 +37,10 @@ module Racecar
|
|
36
37
|
|
37
38
|
protected
|
38
39
|
|
40
|
+
def heartbeat
|
41
|
+
@_consumer.trigger_heartbeat
|
42
|
+
end
|
43
|
+
|
39
44
|
def produce(value, **options)
|
40
45
|
@_producer.produce(value, **options)
|
41
46
|
end
|
data/lib/racecar/runner.rb
CHANGED
@@ -10,8 +10,10 @@ module Racecar
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def stop
|
13
|
-
|
14
|
-
|
13
|
+
Thread.new do
|
14
|
+
processor.teardown
|
15
|
+
consumer.stop unless consumer.nil?
|
16
|
+
end.join
|
15
17
|
end
|
16
18
|
|
17
19
|
def run
|
@@ -64,7 +66,7 @@ module Racecar
|
|
64
66
|
compression_codec: config.producer_compression_codec,
|
65
67
|
)
|
66
68
|
|
67
|
-
processor.configure(producer: producer)
|
69
|
+
processor.configure(consumer: consumer, producer: producer)
|
68
70
|
|
69
71
|
begin
|
70
72
|
if processor.respond_to?(:process)
|
data/lib/racecar/version.rb
CHANGED
data/racecar.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
-
spec.add_runtime_dependency "king_konf", "~> 0.3.
|
23
|
+
spec.add_runtime_dependency "king_konf", "~> 0.3.7"
|
24
24
|
spec.add_runtime_dependency "ruby-kafka", "~> 0.6"
|
25
25
|
|
26
26
|
spec.add_development_dependency "bundler", "~> 1.13"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: racecar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Schierbeck
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2019-01-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: king_konf
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 0.3.
|
20
|
+
version: 0.3.7
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 0.3.
|
27
|
+
version: 0.3.7
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: ruby-kafka
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -135,9 +135,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
135
135
|
version: '0'
|
136
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
137
|
requirements:
|
138
|
-
- - "
|
138
|
+
- - ">"
|
139
139
|
- !ruby/object:Gem::Version
|
140
|
-
version:
|
140
|
+
version: 1.3.1
|
141
141
|
requirements: []
|
142
142
|
rubyforge_project:
|
143
143
|
rubygems_version: 2.7.6
|