phobos 1.6.0 → 1.6.1
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 +2 -2
- data/lib/phobos/actions/process_message.rb +4 -1
- data/lib/phobos/test/helper.rb +15 -7
- data/lib/phobos/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e7de0ef712ba1636a2c66ceb7fbfa159e479c87
|
4
|
+
data.tar.gz: 5bbaa97f07e0f6aa5825b49220daa2f6cac239dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ffa62ee7edcd651dabc33fa6f3bfc96cf3ab30076b49254d89e1c6f0443843159022945c483126fa3e0d5ac8674526a350693405448b327681d0752dc281b31
|
7
|
+
data.tar.gz: aaf894ba3a7ac6c5c01d1b06ee621995fecd5bd0ed368bc28235bdd2a756b55fcb9d7f8955987429e8ed3ae850dc231c4d43ef6fb08e5c611685caf4929729bb
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -455,14 +455,14 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
455
455
|
|
456
456
|
Phobos exports a spec helper that can help you test your consumer. The Phobos lifecycle will conveniently be activated for you with minimal setup required.
|
457
457
|
|
458
|
-
* `process_message(handler:, payload:, metadata
|
458
|
+
* `process_message(handler:, payload:, metadata: {}, encoding: nil)` - Invokes your handler with payload and metadata, using a dummy listener (encoding and metadata are optional).
|
459
459
|
|
460
460
|
```ruby
|
461
461
|
require 'spec_helper'
|
462
462
|
|
463
463
|
describe MyConsumer do
|
464
464
|
let(:payload) { 'foo' }
|
465
|
-
let(:metadata) {
|
465
|
+
let(:metadata) { Hash(foo: 'bar') }
|
466
466
|
|
467
467
|
it 'consumes my message' do
|
468
468
|
expect(described_class).to receive(:around_consume).with(payload, metadata).once.and_call_original
|
@@ -57,16 +57,19 @@ module Phobos
|
|
57
57
|
|
58
58
|
def process_message(payload)
|
59
59
|
instrument('listener.process_message', @metadata) do |metadata|
|
60
|
+
consume_result = nil
|
60
61
|
time_elapsed = measure do
|
61
62
|
handler = @listener.handler_class.new
|
62
63
|
preprocessed_payload = handler.before_consume(payload)
|
63
64
|
|
64
65
|
@listener.handler_class.around_consume(preprocessed_payload, @metadata) do
|
65
|
-
handler.consume(preprocessed_payload, @metadata)
|
66
|
+
consume_result = handler.consume(preprocessed_payload, @metadata)
|
66
67
|
end
|
67
68
|
end
|
68
69
|
|
69
70
|
metadata.merge!(time_elapsed: time_elapsed)
|
71
|
+
|
72
|
+
consume_result
|
70
73
|
end
|
71
74
|
end
|
72
75
|
end
|
data/lib/phobos/test/helper.rb
CHANGED
@@ -1,21 +1,29 @@
|
|
1
1
|
module Phobos
|
2
2
|
module Test
|
3
3
|
module Helper
|
4
|
-
|
4
|
+
TOPIC = 'test-topic'
|
5
|
+
GROUP = 'test-group'
|
5
6
|
|
6
|
-
def process_message(handler:, payload:, metadata
|
7
|
+
def process_message(handler:, payload:, metadata: {}, force_encoding: nil)
|
7
8
|
listener = Phobos::Listener.new(
|
8
9
|
handler: handler,
|
9
|
-
group_id:
|
10
|
-
topic:
|
10
|
+
group_id: GROUP,
|
11
|
+
topic: TOPIC,
|
11
12
|
force_encoding: force_encoding
|
12
13
|
)
|
13
14
|
|
15
|
+
message = Kafka::FetchedMessage.new(
|
16
|
+
value: payload,
|
17
|
+
key: nil,
|
18
|
+
topic: TOPIC,
|
19
|
+
partition: 0,
|
20
|
+
offset: 13,
|
21
|
+
)
|
22
|
+
|
14
23
|
Phobos::Actions::ProcessMessage.new(
|
15
24
|
listener: listener,
|
16
|
-
message:
|
17
|
-
|
18
|
-
encoding: listener.encoding
|
25
|
+
message: message,
|
26
|
+
listener_metadata: metadata
|
19
27
|
).execute
|
20
28
|
end
|
21
29
|
end
|
data/lib/phobos/version.rb
CHANGED