racecar 0.3.5 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +41 -6
- data/examples/producing_consumer.rb +9 -0
- data/lib/racecar/consumer.rb +10 -0
- data/lib/racecar/runner.rb +7 -0
- data/lib/racecar/version.rb +1 -1
- data/racecar.gemspec +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 296b4a32eb01dc8846049c0809af8bf34cf8c1f5
|
4
|
+
data.tar.gz: 0ec2243f458fbcd25a399d0920743b402a192886
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c902215fbae7a6a9bf06bc3f1e68194b016f01283e3a13e0ba7e1949c3c902630aaedf9a3776806867219a0ce1f8097ca394e8ea3fd5500f2a4ba1ee58ab96c
|
7
|
+
data.tar.gz: 324330b9f6efeda4b769817bc54783f95d699f103121c117692b0d4b32e89373575081c7f1edad43dfb625bff3b95957f0245a96c5bc69c6daf0b91daa3673d1
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -10,12 +10,13 @@ The framework is based on [ruby-kafka](https://github.com/zendesk/ruby-kafka), w
|
|
10
10
|
2. [Usage](#usage)
|
11
11
|
1. [Creating consumers](#creating-consumers)
|
12
12
|
2. [Running consumers](#running-consumers)
|
13
|
-
3. [
|
14
|
-
4. [
|
15
|
-
5. [
|
16
|
-
6. [
|
17
|
-
7. [
|
18
|
-
8. [
|
13
|
+
3. [Producing messages](#producing-messages)
|
14
|
+
4. [Configuration](#configuration)
|
15
|
+
5. [Testing consumers](#testing-consumers)
|
16
|
+
6. [Deploying consumers](#deploying-consumers)
|
17
|
+
7. [Handling errors](#handling-errors)
|
18
|
+
8. [Logging](#logging)
|
19
|
+
9. [Operations](#operations)
|
19
20
|
3. [Development](#development)
|
20
21
|
4. [Contributing](#contributing)
|
21
22
|
5. [Support and Discussion](#support-and-discussion)
|
@@ -174,6 +175,31 @@ Racecar is first and foremost an executable _consumer runner_. The `racecar` exe
|
|
174
175
|
|
175
176
|
The first time you execute `racecar` with a consumer class a _consumer group_ will be created with a group id derived from the class name (this can be configured). If you start `racecar` with the same consumer class argument multiple times, the processes will join the existing group – even if you start them on other nodes. You will typically want to have at least two consumers in each of your groups – preferably on separate nodes – in order to deal with failures.
|
176
177
|
|
178
|
+
### Producing messages
|
179
|
+
|
180
|
+
**WARNING:** This is an alpha feature, and could cause weird and unpredictable errors. Use with caution.
|
181
|
+
|
182
|
+
Consumers can produce messages themselves, allowing for powerful stream processing applications that transform and filter message streams. The API for this is simple:
|
183
|
+
|
184
|
+
```ruby
|
185
|
+
class GeoCodingConsumer < Racecar::Consumer
|
186
|
+
subscribes_to "pageviews"
|
187
|
+
|
188
|
+
def process(message)
|
189
|
+
pageview = JSON.parse(message.value)
|
190
|
+
ip_address = pageview.fetch("ip_address")
|
191
|
+
|
192
|
+
country = GeoCode.country(ip_address)
|
193
|
+
|
194
|
+
# Enrich the original message:
|
195
|
+
pageview["country"] = country
|
196
|
+
|
197
|
+
# The `produce` method enqueues a message to be delivered after #process
|
198
|
+
# returns. It won't actually deliver the message.
|
199
|
+
produce(JSON.dump(pageview), topic: "pageviews-with-country")
|
200
|
+
end
|
201
|
+
end
|
202
|
+
```
|
177
203
|
|
178
204
|
### Configuration
|
179
205
|
|
@@ -183,6 +209,15 @@ Racecar provides a flexible way to configure your consumer in a way that feels a
|
|
183
209
|
|
184
210
|
It's also possible to configure Racecar using environment variables. For any given configuration key, there should be a corresponding environment variable with the prefix `RACECAR_`, in upper case. For instance, in order to configure the client id, set `RACECAR_CLIENT_ID=some-id` in the process in which the Racecar consumer is launched. You can set `brokers` by passing a comma-separated list, e.g. `RACECAR_BROKERS=kafka1:9092,kafka2:9092,kafka3:9092`.
|
185
211
|
|
212
|
+
Finally, you can configure Racecar directly in Ruby. The file `config/racecar.rb` will be automatically loaded if it exists; in it, you can configure Racecar using a simple API:
|
213
|
+
|
214
|
+
```ruby
|
215
|
+
Racecar.configure do |config|
|
216
|
+
# Each config variable can be set using a writer attribute.
|
217
|
+
config.brokers = ServiceDiscovery.find("kafka-brokers")
|
218
|
+
end
|
219
|
+
```
|
220
|
+
|
186
221
|
#### Basic configuration
|
187
222
|
|
188
223
|
* `brokers` – A list of Kafka brokers in the cluster that you're consuming from. Defaults to `localhost` on port 9092, the default Kafka port.
|
data/lib/racecar/consumer.rb
CHANGED
data/lib/racecar/runner.rb
CHANGED
@@ -22,6 +22,7 @@ module Racecar
|
|
22
22
|
connect_timeout: config.connect_timeout,
|
23
23
|
socket_timeout: config.socket_timeout,
|
24
24
|
ssl_ca_cert: config.ssl_ca_cert,
|
25
|
+
ssl_ca_cert_file_path: config.ssl_ca_cert_file_path,
|
25
26
|
ssl_client_cert: config.ssl_client_cert,
|
26
27
|
ssl_client_cert_key: config.ssl_client_cert_key,
|
27
28
|
sasl_plain_username: config.sasl_plain_username,
|
@@ -52,6 +53,10 @@ module Racecar
|
|
52
53
|
)
|
53
54
|
end
|
54
55
|
|
56
|
+
# Configure the consumer with a producer so it can produce messages.
|
57
|
+
producer = kafka.producer
|
58
|
+
processor.configure(producer: producer)
|
59
|
+
|
55
60
|
begin
|
56
61
|
if processor.respond_to?(:process)
|
57
62
|
consumer.each_message(max_wait_time: config.max_wait_time) do |message|
|
@@ -68,6 +73,7 @@ module Racecar
|
|
68
73
|
|
69
74
|
@instrumenter.instrument("process_message.racecar", payload) do
|
70
75
|
processor.process(message)
|
76
|
+
producer.deliver_messages
|
71
77
|
end
|
72
78
|
end
|
73
79
|
elsif processor.respond_to?(:process_batch)
|
@@ -86,6 +92,7 @@ module Racecar
|
|
86
92
|
|
87
93
|
@instrumenter.instrument("process_batch.racecar", payload) do
|
88
94
|
processor.process_batch(batch)
|
95
|
+
producer.deliver_messages
|
89
96
|
end
|
90
97
|
end
|
91
98
|
else
|
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.1.
|
23
|
+
spec.add_runtime_dependency "king_konf", "~> 0.1.9"
|
24
24
|
spec.add_runtime_dependency "ruby-kafka", "~> 0.4"
|
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.3.
|
4
|
+
version: 0.3.6
|
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: 2018-01-04 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.1.
|
20
|
+
version: 0.1.9
|
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.1.
|
27
|
+
version: 0.1.9
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: ruby-kafka
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,6 +103,7 @@ files:
|
|
103
103
|
- bin/setup
|
104
104
|
- examples/batch_consumer.rb
|
105
105
|
- examples/cat_consumer.rb
|
106
|
+
- examples/producing_consumer.rb
|
106
107
|
- exe/racecar
|
107
108
|
- exe/racecarctl
|
108
109
|
- lib/generators/racecar/consumer_generator.rb
|