phobos 1.8.3.pre.beta1 → 1.8.3.pre.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +19 -1
- data/lib/phobos/actions/process_batch_inline.rb +16 -13
- data/lib/phobos/actions/process_message.rb +2 -1
- data/lib/phobos/batch_message.rb +4 -3
- data/lib/phobos/producer.rb +12 -11
- data/lib/phobos/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d9c3d6d826d8865116eeeef7183e1d3eb60862d4673fb10c0464577707e1a8a
|
4
|
+
data.tar.gz: 7317cdfb2c8516cfa837f52c41d14181987ccdd12698eccfb8119def24c24ab1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f4eb5b010f7c628db69ddbf4c5cc4237d1afff4f8a42b462e9e47cf835a2bbf2950c827865640bb3456009a7fcdd2b900df3d1d758206e82ddb774ffef5c202
|
7
|
+
data.tar.gz: 5b3a4b2ac5755a296097c52ded7e5ead4fc866250ff24c16ca75e620dd056c315dbeba1055fee1c4f509d88619b1bb0aaea7c8b6cf61861ac72ed1fab6aa1ad7
|
data/CHANGELOG.md
CHANGED
@@ -3,9 +3,13 @@ All notable changes to this project will be documented in this file.
|
|
3
3
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
6
|
-
|
6
|
+
``
|
7
7
|
## UNRELEASED
|
8
8
|
|
9
|
+
## [1.8.3-beta2] - 2019-11-15
|
10
|
+
- Add support for message headers in both produced and consumed
|
11
|
+
messages and batches.
|
12
|
+
|
9
13
|
## [1.8.3-beta1] - 2019-11-11
|
10
14
|
- Automatically heartbeat after every message if necessary in batch
|
11
15
|
mode.
|
data/README.md
CHANGED
@@ -139,6 +139,8 @@ A handler is required to implement the method `#consume(payload, metadata)`.
|
|
139
139
|
|
140
140
|
Instances of your handler will be created for every message, so keep a constructor without arguments. If `consume` raises an exception, Phobos will retry the message indefinitely, applying the back off configuration presented in the configuration file. The `metadata` hash will contain a key called `retry_count` with the current number of retries for this message. To skip a message, simply return from `#consume`.
|
141
141
|
|
142
|
+
The `metadata` hash will also contain a key called `headers` with the headers of the consumed message.
|
143
|
+
|
142
144
|
When the listener starts, the class method `.start` will be called with the `kafka_client` used by the listener. Use this hook as a chance to setup necessary code for your handler. The class method `.stop` will be called during listener shutdown.
|
143
145
|
|
144
146
|
```ruby
|
@@ -233,6 +235,9 @@ and your handler must include `BatchHandler`. Using a delivery method of `batch`
|
|
233
235
|
assumes that you are still processing the messages one at a time and should
|
234
236
|
use `Handler`.
|
235
237
|
|
238
|
+
When using `inline_batch`, each instance of `Phobos::BatchMessage` will contain an
|
239
|
+
instance method `headers` with the headers for that message.
|
240
|
+
|
236
241
|
```ruby
|
237
242
|
class MyBatchHandler
|
238
243
|
include Phobos::BatchHandler
|
@@ -282,6 +287,19 @@ my.producer.publish('topic', 'message-payload', 'partition and message key')
|
|
282
287
|
MyProducer.producer.publish('topic', 'message-payload', 'partition and message key')
|
283
288
|
```
|
284
289
|
|
290
|
+
The signature for the `publish` method is as follows:
|
291
|
+
|
292
|
+
```ruby
|
293
|
+
def publish(topic, payload, key = nil, partition_key = nil, headers = nil)
|
294
|
+
```
|
295
|
+
|
296
|
+
To produce messages with headers, 5 arguments will have to be passed to `publish`:
|
297
|
+
|
298
|
+
```ruby
|
299
|
+
my = MyProducer.new
|
300
|
+
my.producer.publish('topic', 'message-payload', 'partition and message key', nil, { header_1: 'value 1' })
|
301
|
+
```
|
302
|
+
|
285
303
|
It is also possible to publish several messages at once:
|
286
304
|
|
287
305
|
```ruby
|
@@ -290,7 +308,7 @@ MyProducer
|
|
290
308
|
.publish_list([
|
291
309
|
{ topic: 'A', payload: 'message-1', key: '1' },
|
292
310
|
{ topic: 'B', payload: 'message-2', key: '2' },
|
293
|
-
{ topic: 'B', payload: 'message-3', key: '3' }
|
311
|
+
{ topic: 'B', payload: 'message-3', key: '3', headers: { header_1: 'value 1', header_2: 'value 2' } }
|
294
312
|
])
|
295
313
|
```
|
296
314
|
|
@@ -24,17 +24,10 @@ module Phobos
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def execute
|
27
|
-
|
28
|
-
Phobos::BatchMessage.new(
|
29
|
-
key: message.key,
|
30
|
-
partition: message.partition,
|
31
|
-
offset: message.offset,
|
32
|
-
payload: force_encoding(message.value)
|
33
|
-
)
|
34
|
-
end
|
27
|
+
batch = @batch.messages.map { |message| instantiate_batch_message(message) }
|
35
28
|
|
36
29
|
begin
|
37
|
-
process_batch(
|
30
|
+
process_batch(batch)
|
38
31
|
rescue StandardError => e
|
39
32
|
handle_error(e, 'listener.retry_handler_error_batch',
|
40
33
|
"error processing inline batch, waiting #{backoff_interval}s")
|
@@ -44,14 +37,24 @@ module Phobos
|
|
44
37
|
|
45
38
|
private
|
46
39
|
|
47
|
-
def
|
40
|
+
def instantiate_batch_message(message)
|
41
|
+
Phobos::BatchMessage.new(
|
42
|
+
key: message.key,
|
43
|
+
partition: message.partition,
|
44
|
+
offset: message.offset,
|
45
|
+
payload: force_encoding(message.value),
|
46
|
+
headers: message.headers
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
def process_batch(batch)
|
48
51
|
instrument('listener.process_batch_inline', @metadata) do |_metadata|
|
49
52
|
handler = @listener.handler_class.new
|
50
53
|
|
51
|
-
|
52
|
-
consume_block = proc { handler.consume_batch(
|
54
|
+
preprocessed_batch = handler.before_consume_batch(batch, @metadata)
|
55
|
+
consume_block = proc { handler.consume_batch(preprocessed_batch, @metadata) }
|
53
56
|
|
54
|
-
handler.around_consume_batch(
|
57
|
+
handler.around_consume_batch(preprocessed_batch, @metadata, &consume_block)
|
55
58
|
end
|
56
59
|
end
|
57
60
|
end
|
data/lib/phobos/batch_message.rb
CHANGED
@@ -2,17 +2,18 @@
|
|
2
2
|
|
3
3
|
module Phobos
|
4
4
|
class BatchMessage
|
5
|
-
attr_accessor :key, :partition, :offset, :payload
|
5
|
+
attr_accessor :key, :partition, :offset, :payload, :headers
|
6
6
|
|
7
|
-
def initialize(key:, partition:, offset:, payload:)
|
7
|
+
def initialize(key:, partition:, offset:, payload:, headers:)
|
8
8
|
@key = key
|
9
9
|
@partition = partition
|
10
10
|
@offset = offset
|
11
11
|
@payload = payload
|
12
|
+
@headers = headers
|
12
13
|
end
|
13
14
|
|
14
15
|
def ==(other)
|
15
|
-
[:key, :partition, :offset, :payload].all? do |s|
|
16
|
+
[:key, :partition, :offset, :payload, :headers].all? do |s|
|
16
17
|
public_send(s) == other.public_send(s)
|
17
18
|
end
|
18
19
|
end
|
data/lib/phobos/producer.rb
CHANGED
@@ -15,18 +15,18 @@ module Phobos
|
|
15
15
|
@host_obj = host_obj
|
16
16
|
end
|
17
17
|
|
18
|
-
def publish(topic, payload, key = nil, partition_key = nil)
|
19
|
-
class_producer.publish(topic, payload, key, partition_key)
|
18
|
+
def publish(topic, payload, key = nil, partition_key = nil, headers = nil)
|
19
|
+
class_producer.publish(topic, payload, key, partition_key, headers)
|
20
20
|
end
|
21
21
|
|
22
|
-
def async_publish(topic, payload, key = nil, partition_key = nil)
|
23
|
-
class_producer.async_publish(topic, payload, key, partition_key)
|
22
|
+
def async_publish(topic, payload, key = nil, partition_key = nil, headers = nil)
|
23
|
+
class_producer.async_publish(topic, payload, key, partition_key, headers)
|
24
24
|
end
|
25
25
|
|
26
|
-
# @param messages [Array(Hash(:topic, :payload, :key))]
|
26
|
+
# @param messages [Array(Hash(:topic, :payload, :key, :headers))]
|
27
27
|
# e.g.: [
|
28
|
-
# { topic: 'A', payload: 'message-1', key: '1' },
|
29
|
-
# { topic: 'B', payload: 'message-2', key: '2' }
|
28
|
+
# { topic: 'A', payload: 'message-1', key: '1', headers: { foo: 'bar' } },
|
29
|
+
# { topic: 'B', payload: 'message-2', key: '2', headers: { foo: 'bar' } }
|
30
30
|
# ]
|
31
31
|
#
|
32
32
|
def publish_list(messages)
|
@@ -86,9 +86,9 @@ module Phobos
|
|
86
86
|
producer_store[:sync_producer] = nil
|
87
87
|
end
|
88
88
|
|
89
|
-
def publish(topic, payload, key = nil, partition_key = nil)
|
89
|
+
def publish(topic, payload, key = nil, partition_key = nil, headers = nil)
|
90
90
|
publish_list([{ topic: topic, payload: payload, key: key,
|
91
|
-
partition_key: partition_key }])
|
91
|
+
partition_key: partition_key, headers: headers }])
|
92
92
|
end
|
93
93
|
|
94
94
|
def publish_list(messages)
|
@@ -109,9 +109,9 @@ module Phobos
|
|
109
109
|
producer_store[:async_producer]
|
110
110
|
end
|
111
111
|
|
112
|
-
def async_publish(topic, payload, key = nil, partition_key = nil)
|
112
|
+
def async_publish(topic, payload, key = nil, partition_key = nil, headers = nil)
|
113
113
|
async_publish_list([{ topic: topic, payload: payload, key: key,
|
114
|
-
partition_key: partition_key }])
|
114
|
+
partition_key: partition_key, headers: headers }])
|
115
115
|
end
|
116
116
|
|
117
117
|
def async_publish_list(messages)
|
@@ -144,6 +144,7 @@ module Phobos
|
|
144
144
|
partition_key = message[:partition_key] || message[:key]
|
145
145
|
producer.produce(message[:payload], topic: message[:topic],
|
146
146
|
key: message[:key],
|
147
|
+
headers: message[:headers],
|
147
148
|
partition_key: partition_key)
|
148
149
|
end
|
149
150
|
end
|
data/lib/phobos/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phobos
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.3.pre.
|
4
|
+
version: 1.8.3.pre.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Túlio Ornelas
|
@@ -15,7 +15,7 @@ authors:
|
|
15
15
|
autorequire:
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
|
-
date: 2019-11-
|
18
|
+
date: 2019-11-15 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: bundler
|