racecar 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 227816cc1a2d86b97ae477dba46ef474c18b48e1
4
- data.tar.gz: 6779b99acc433787743ac1e45963be0931458f11
3
+ metadata.gz: 296b4a32eb01dc8846049c0809af8bf34cf8c1f5
4
+ data.tar.gz: 0ec2243f458fbcd25a399d0920743b402a192886
5
5
  SHA512:
6
- metadata.gz: 84f6a4fa70d0e680d17d4a6418c752353443263444528fd0d37a85e89b4005637627243b0150486a85b0439b8e1dd3b748e8f2a6d9296ee3c041f40de3b3cc03
7
- data.tar.gz: 8d6262f0499bb2aa84d8beada1710fd32a97fad17aa8853f07cc90d38d739c1f65a5f40a9e4c0a409c9ca2e3f7a60eade093a0ed9d76569716e37d45a72b14d5
6
+ metadata.gz: 9c902215fbae7a6a9bf06bc3f1e68194b016f01283e3a13e0ba7e1949c3c902630aaedf9a3776806867219a0ce1f8097ca394e8ea3fd5500f2a4ba1ee58ab96c
7
+ data.tar.gz: 324330b9f6efeda4b769817bc54783f95d699f103121c117692b0d4b32e89373575081c7f1edad43dfb625bff3b95957f0245a96c5bc69c6daf0b91daa3673d1
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## racecar v0.3.6
6
+
7
+ * Allow producing messages (alpha).
8
+
5
9
  ## racecar v0.3.5
6
10
 
7
11
  * Instrument using ActiveSupport::Notifications (#43).
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. [Configuration](#configuration)
14
- 4. [Testing consumers](#testing-consumers)
15
- 5. [Deploying consumers](#deploying-consumers)
16
- 6. [Handling errors](#handling-errors)
17
- 7. [Logging](#logging)
18
- 8. [Operations](#operations)
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.
@@ -0,0 +1,9 @@
1
+ class ProducingConsumer < Racecar::Consumer
2
+ subscribes_to "messages", start_from_beginning: false
3
+
4
+ def process(message)
5
+ value = message.value.reverse
6
+
7
+ produce value, topic: "reverse-messages"
8
+ end
9
+ end
@@ -23,6 +23,16 @@ module Racecar
23
23
  end
24
24
  end
25
25
 
26
+ def configure(producer:)
27
+ @_producer = producer
28
+ end
29
+
26
30
  def teardown; end
31
+
32
+ protected
33
+
34
+ def produce(value, topic:)
35
+ @_producer.produce(value, topic: topic)
36
+ end
27
37
  end
28
38
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Racecar
2
- VERSION = "0.3.5"
2
+ VERSION = "0.3.6"
3
3
  end
@@ -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.8"
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.5
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: 2017-12-21 00:00:00.000000000 Z
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.8
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.8
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