phobos 1.9.0.pre.beta1 → 1.9.0.pre.beta2
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 +5 -0
- data/README.md +6 -20
- data/lib/phobos/actions/process_batch_inline.rb +20 -2
- data/lib/phobos/actions/process_message.rb +30 -13
- data/lib/phobos/batch_handler.rb +2 -6
- data/lib/phobos/handler.rb +2 -6
- 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: f2b2f9eeb44e40d9cb01add121e7b388c66e99f5482e5f2ec78bb7bc3263bd32
|
4
|
+
data.tar.gz: 796484971553a2b19edc18f0e4192ffaece1de0c27894bfa0344b0af29fc3f23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f2f422bff9b56354c1378c283090277a1af164b2b8a3f9a038c85a25157131e1e2cd005d37e72ba21d921620521210020859368b42851dc110043395052ab11
|
7
|
+
data.tar.gz: dbd23e7210111e63921854bf279c0f64aa9a4ba426f24af897924a1c6a76cb24a19be4c35db1105013c0d0de3c6a6e2bb73272df6cce9b24e4dce9c9a445becf
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
6
6
|
``
|
7
7
|
## UNRELEASED
|
8
8
|
|
9
|
+
## [1.9.0-beta2] - 2020-01-09
|
10
|
+
|
11
|
+
- Allow `around_consume` to yield payload and metadata, and deprecate
|
12
|
+
`before_consume` and `around_consume` that does not yield anything.
|
13
|
+
|
9
14
|
## [1.9.0-beta1] - 2019-12-18
|
10
15
|
- Update `publish` and `async_publish` to use keyword arguments
|
11
16
|
instead of positional ones. Deprecate positional arguments
|
data/README.md
CHANGED
@@ -169,7 +169,7 @@ class MyHandler
|
|
169
169
|
|
170
170
|
def around_consume(payload, metadata)
|
171
171
|
Phobos.logger.info "consuming..."
|
172
|
-
output = yield
|
172
|
+
output = yield payload, metadata
|
173
173
|
Phobos.logger.info "done, output: #{output}"
|
174
174
|
end
|
175
175
|
|
@@ -187,7 +187,7 @@ class MyHandler
|
|
187
187
|
|
188
188
|
def self.around_consume(payload, metadata)
|
189
189
|
Phobos.logger.info "consuming..."
|
190
|
-
output = yield
|
190
|
+
output = yield payload, metadata
|
191
191
|
Phobos.logger.info "done, output: #{output}"
|
192
192
|
end
|
193
193
|
|
@@ -197,18 +197,7 @@ class MyHandler
|
|
197
197
|
end
|
198
198
|
```
|
199
199
|
|
200
|
-
|
201
|
-
|
202
|
-
```ruby
|
203
|
-
class MyHandler
|
204
|
-
include Phobos::Handler
|
205
|
-
|
206
|
-
def before_consume(payload, metadata)
|
207
|
-
# optionally preprocess payload
|
208
|
-
payload
|
209
|
-
end
|
210
|
-
end
|
211
|
-
```
|
200
|
+
Note: Previous versions used a `before_consume` method to pre-process the payload. This is still supported, but deprecated. Going forward, `around_consume` should yield the payload and metadata back to the calling code, allowing it to act as a pre-processor, e.g. by decoding Avro messages into Ruby hashes.
|
212
201
|
|
213
202
|
Take a look at the examples folder for some ideas.
|
214
203
|
|
@@ -218,7 +207,7 @@ The hander life cycle can be illustrated as:
|
|
218
207
|
|
219
208
|
or optionally,
|
220
209
|
|
221
|
-
`.start` -> `#
|
210
|
+
`.start` -> `#around_consume` [ `#consume` ] -> `.stop`
|
222
211
|
|
223
212
|
#### Batch Consumption
|
224
213
|
|
@@ -242,14 +231,12 @@ instance method `headers` with the headers for that message.
|
|
242
231
|
class MyBatchHandler
|
243
232
|
include Phobos::BatchHandler
|
244
233
|
|
245
|
-
def
|
234
|
+
def around_consume_batch(payloads, metadata)
|
246
235
|
payloads.each do |p|
|
247
236
|
p.payload[:timestamp] = Time.zone.now
|
248
237
|
end
|
249
|
-
end
|
250
238
|
|
251
|
-
|
252
|
-
yield
|
239
|
+
yield payloads, metadata
|
253
240
|
end
|
254
241
|
|
255
242
|
def consume_batch(payloads, metadata)
|
@@ -625,7 +612,6 @@ describe MyConsumer do
|
|
625
612
|
|
626
613
|
it 'consumes my message' do
|
627
614
|
expect_any_instance_of(described_class).to receive(:around_consume).with(payload, metadata).once.and_call_original
|
628
|
-
expect_any_instance_of(described_class).to receive(:before_consume).with(payload, metadata).once.and_call_original
|
629
615
|
expect_any_instance_of(described_class).to receive(:consume).with(payload, metadata).once.and_call_original
|
630
616
|
|
631
617
|
process_message(handler: described_class, payload: payload, metadata: metadata)
|
@@ -47,12 +47,30 @@ module Phobos
|
|
47
47
|
)
|
48
48
|
end
|
49
49
|
|
50
|
+
def preprocess(batch, handler)
|
51
|
+
if handler.respond_to?(:before_consume_batch)
|
52
|
+
Phobos.deprecate('before_consume_batch is deprecated and will be removed in 2.0. \
|
53
|
+
Use around_consume_batch and yield payloads and metadata objects.')
|
54
|
+
handler.before_consume_batch(batch, @metadata)
|
55
|
+
else
|
56
|
+
batch
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
50
60
|
def process_batch(batch)
|
51
61
|
instrument('listener.process_batch_inline', @metadata) do |_metadata|
|
52
62
|
handler = @listener.handler_class.new
|
53
63
|
|
54
|
-
preprocessed_batch =
|
55
|
-
consume_block = proc {
|
64
|
+
preprocessed_batch = preprocess(batch, handler)
|
65
|
+
consume_block = proc { |around_batch, around_metadata|
|
66
|
+
if around_batch
|
67
|
+
handler.consume_batch(around_batch, around_metadata)
|
68
|
+
else
|
69
|
+
Phobos.deprecate('Calling around_consume_batch without yielding payloads \
|
70
|
+
and metadata is deprecated and will be removed in 2.0.')
|
71
|
+
handler.consume_batch(preprocessed_batch, @metadata)
|
72
|
+
end
|
73
|
+
}
|
56
74
|
|
57
75
|
handler.around_consume_batch(preprocessed_batch, @metadata, &consume_block)
|
58
76
|
end
|
@@ -35,33 +35,50 @@ module Phobos
|
|
35
35
|
|
36
36
|
private
|
37
37
|
|
38
|
+
def preprocess(payload, handler)
|
39
|
+
if handler.respond_to?(:before_consume)
|
40
|
+
Phobos.deprecate('before_consume is deprecated and will be removed in 2.0. \
|
41
|
+
Use around_consume and yield payload and metadata objects.')
|
42
|
+
begin
|
43
|
+
handler.before_consume(payload, @metadata)
|
44
|
+
rescue ArgumentError
|
45
|
+
handler.before_consume(payload)
|
46
|
+
end
|
47
|
+
else
|
48
|
+
payload
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def consume_block(payload, handler)
|
53
|
+
proc { |around_payload, around_metadata|
|
54
|
+
if around_payload
|
55
|
+
handler.consume(around_payload, around_metadata)
|
56
|
+
else
|
57
|
+
Phobos.deprecate('Calling around_consume without yielding payload and metadata \
|
58
|
+
is deprecated and will be removed in 2.0.')
|
59
|
+
handler.consume(payload, @metadata)
|
60
|
+
end
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
38
64
|
def process_message(payload)
|
39
65
|
instrument('listener.process_message', @metadata) do
|
40
66
|
handler = @listener.handler_class.new
|
41
67
|
|
42
|
-
preprocessed_payload =
|
43
|
-
|
68
|
+
preprocessed_payload = preprocess(payload, handler)
|
69
|
+
block = consume_block(preprocessed_payload, handler)
|
44
70
|
|
45
71
|
if @listener.handler_class.respond_to?(:around_consume)
|
46
72
|
# around_consume class method implementation
|
47
73
|
Phobos.deprecate('around_consume has been moved to instance method, please update '\
|
48
74
|
'your consumer. This will not be backwards compatible in the future.')
|
49
|
-
@listener.handler_class.around_consume(preprocessed_payload, @metadata, &
|
75
|
+
@listener.handler_class.around_consume(preprocessed_payload, @metadata, &block)
|
50
76
|
else
|
51
77
|
# around_consume instance method implementation
|
52
|
-
handler.around_consume(preprocessed_payload, @metadata, &
|
78
|
+
handler.around_consume(preprocessed_payload, @metadata, &block)
|
53
79
|
end
|
54
80
|
end
|
55
81
|
end
|
56
|
-
|
57
|
-
def before_consume(handler, payload)
|
58
|
-
handler.before_consume(payload, @metadata)
|
59
|
-
rescue ArgumentError
|
60
|
-
Phobos.deprecate('before_consume now expects metadata as second argument, please update '\
|
61
|
-
'your consumer. This will not be backwards compatible in the future.')
|
62
|
-
|
63
|
-
handler.before_consume(payload)
|
64
|
-
end
|
65
82
|
end
|
66
83
|
end
|
67
84
|
end
|
data/lib/phobos/batch_handler.rb
CHANGED
@@ -6,16 +6,12 @@ module Phobos
|
|
6
6
|
base.extend(ClassMethods)
|
7
7
|
end
|
8
8
|
|
9
|
-
def before_consume_batch(payloads, _metadata)
|
10
|
-
payloads
|
11
|
-
end
|
12
|
-
|
13
9
|
def consume_batch(_payloads, _metadata)
|
14
10
|
raise NotImplementedError
|
15
11
|
end
|
16
12
|
|
17
|
-
def around_consume_batch(
|
18
|
-
yield
|
13
|
+
def around_consume_batch(payloads, metadata)
|
14
|
+
yield payloads, metadata
|
19
15
|
end
|
20
16
|
|
21
17
|
module ClassMethods
|
data/lib/phobos/handler.rb
CHANGED
@@ -6,16 +6,12 @@ module Phobos
|
|
6
6
|
base.extend(ClassMethods)
|
7
7
|
end
|
8
8
|
|
9
|
-
def before_consume(payload, _metadata)
|
10
|
-
payload
|
11
|
-
end
|
12
|
-
|
13
9
|
def consume(_payload, _metadata)
|
14
10
|
raise NotImplementedError
|
15
11
|
end
|
16
12
|
|
17
|
-
def around_consume(
|
18
|
-
yield
|
13
|
+
def around_consume(payload, metadata)
|
14
|
+
yield payload, metadata
|
19
15
|
end
|
20
16
|
|
21
17
|
module ClassMethods
|
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.9.0.pre.
|
4
|
+
version: 1.9.0.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:
|
18
|
+
date: 2020-01-09 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: bundler
|