phobos 1.8.3.pre.beta2 → 1.9.0.pre.beta1
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 +8 -6
- data/examples/publishing_messages_without_consumer.rb +1 -1
- data/lib/phobos.rb +2 -1
- data/lib/phobos/actions/process_message.rb +5 -4
- data/lib/phobos/producer.rb +48 -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: 9ac51b2a5d3cdaa995dc2f8dfca3d8597c225c0b311724655712bb1ba7060991
|
4
|
+
data.tar.gz: d58bf202dced7bf24c483b0cd2067e4e13e2a43e8f1cfa756377ccf1cf4861dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b41e84f671b6f59d94bced995a491818468b1932fe22309e55bff1236d5f165c624d65647bc24ce054f5ab41e8ed20a53ffdb04ab21d755a3fa46cc52e9ba24
|
7
|
+
data.tar.gz: 69651f14500c3c0126b55429f0c5fd8bc2118845a6eac07147cd4c7cd87aa12d7f101a79f250cd428747c322ad469121af8a10fe94af3bc1f5fa67c70d0666a6
|
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-beta1] - 2019-12-18
|
10
|
+
- Update `publish` and `async_publish` to use keyword arguments
|
11
|
+
instead of positional ones. Deprecate positional arguments
|
12
|
+
in anticipation of removing them with 2.0.
|
13
|
+
|
9
14
|
## [1.8.3-beta2] - 2019-11-15
|
10
15
|
- Add support for message headers in both produced and consumed
|
11
16
|
messages and batches.
|
data/README.md
CHANGED
@@ -281,25 +281,27 @@ The producer module doesn't pollute your classes with a thousand methods, it inc
|
|
281
281
|
|
282
282
|
```ruby
|
283
283
|
my = MyProducer.new
|
284
|
-
my.producer.publish('topic', 'message-payload', 'partition and message key')
|
284
|
+
my.producer.publish(topic: 'topic', payload: 'message-payload', key: 'partition and message key')
|
285
285
|
|
286
286
|
# The code above has the same effect of this code:
|
287
|
-
MyProducer.producer.publish('topic', 'message-payload', 'partition and message key')
|
287
|
+
MyProducer.producer.publish(topic: 'topic', payload: 'message-payload', key: 'partition and message key')
|
288
288
|
```
|
289
289
|
|
290
290
|
The signature for the `publish` method is as follows:
|
291
291
|
|
292
292
|
```ruby
|
293
|
-
def publish(topic, payload, key
|
293
|
+
def publish(topic: topic, payload: payload, key: nil, partition_key: nil, headers: nil)
|
294
294
|
```
|
295
295
|
|
296
|
-
|
296
|
+
When publishing a message with headers, the `headers` argument must be a hash:
|
297
297
|
|
298
298
|
```ruby
|
299
299
|
my = MyProducer.new
|
300
|
-
my.producer.publish('topic', 'message-payload', 'partition and message key',
|
300
|
+
my.producer.publish(topic: 'topic', payload: 'message-payload', key: 'partition and message key', headers: { header_1: 'value 1' })
|
301
301
|
```
|
302
302
|
|
303
|
+
Older versions of Phobos provided a `publish` method that accepted positional arguments. That version is still supported but it's soon to be deprecated in favour of the keyword arguments version.
|
304
|
+
|
303
305
|
It is also possible to publish several messages at once:
|
304
306
|
|
305
307
|
```ruby
|
@@ -328,7 +330,7 @@ class MyHandler
|
|
328
330
|
PUBLISH_TO = 'topic2'
|
329
331
|
|
330
332
|
def consume(payload, metadata)
|
331
|
-
producer.async_publish(PUBLISH_TO, {key: 'value'}.to_json)
|
333
|
+
producer.async_publish(topic: PUBLISH_TO, payload: {key: 'value'}.to_json)
|
332
334
|
end
|
333
335
|
end
|
334
336
|
```
|
data/lib/phobos.rb
CHANGED
@@ -44,8 +44,8 @@ module Phobos
|
|
44
44
|
|
45
45
|
if @listener.handler_class.respond_to?(:around_consume)
|
46
46
|
# around_consume class method implementation
|
47
|
-
Phobos.deprecate('around_consume has been moved to instance method, '\
|
48
|
-
|
47
|
+
Phobos.deprecate('around_consume has been moved to instance method, please update '\
|
48
|
+
'your consumer. This will not be backwards compatible in the future.')
|
49
49
|
@listener.handler_class.around_consume(preprocessed_payload, @metadata, &consume_block)
|
50
50
|
else
|
51
51
|
# around_consume instance method implementation
|
@@ -57,8 +57,9 @@ module Phobos
|
|
57
57
|
def before_consume(handler, payload)
|
58
58
|
handler.before_consume(payload, @metadata)
|
59
59
|
rescue ArgumentError
|
60
|
-
Phobos.deprecate('before_consume now expects metadata as second argument, '\
|
61
|
-
|
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
|
+
|
62
63
|
handler.before_consume(payload)
|
63
64
|
end
|
64
65
|
end
|
data/lib/phobos/producer.rb
CHANGED
@@ -11,16 +11,28 @@ module Phobos
|
|
11
11
|
end
|
12
12
|
|
13
13
|
class PublicAPI
|
14
|
+
MissingRequiredArgumentsError = Class.new(StandardError) do
|
15
|
+
def initialize
|
16
|
+
super('You need to provide a topic name and a payload')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
14
20
|
def initialize(host_obj)
|
15
21
|
@host_obj = host_obj
|
16
22
|
end
|
17
23
|
|
18
|
-
def publish(
|
19
|
-
|
24
|
+
def publish(*args, **kwargs)
|
25
|
+
Phobos.deprecate(deprecate_positional_args_message('publish')) if kwargs.empty?
|
26
|
+
|
27
|
+
args = normalize_arguments(*args, **kwargs)
|
28
|
+
class_producer.publish(**args)
|
20
29
|
end
|
21
30
|
|
22
|
-
def async_publish(
|
23
|
-
|
31
|
+
def async_publish(*args, **kwargs)
|
32
|
+
Phobos.deprecate(deprecate_positional_args_message('async_publish')) if kwargs.empty?
|
33
|
+
|
34
|
+
args = normalize_arguments(*args, **kwargs)
|
35
|
+
class_producer.async_publish(**args)
|
24
36
|
end
|
25
37
|
|
26
38
|
# @param messages [Array(Hash(:topic, :payload, :key, :headers))]
|
@@ -42,6 +54,36 @@ module Phobos
|
|
42
54
|
def class_producer
|
43
55
|
@host_obj.class.producer
|
44
56
|
end
|
57
|
+
|
58
|
+
# rubocop:disable Metrics/ParameterLists
|
59
|
+
def normalize_arguments(p_topic = nil, p_payload = nil, p_key = nil,
|
60
|
+
p_partition_key = nil, p_headers = {},
|
61
|
+
**kwargs)
|
62
|
+
{}.tap do |args|
|
63
|
+
{
|
64
|
+
topic: p_topic,
|
65
|
+
payload: p_payload,
|
66
|
+
key: p_key,
|
67
|
+
partition_key: p_partition_key,
|
68
|
+
headers: p_headers
|
69
|
+
}.each { |k, v| args[k] = kwargs[k] || v }
|
70
|
+
|
71
|
+
raise MissingRequiredArgumentsError if [:topic, :payload].any? { |k| args[k].nil? }
|
72
|
+
|
73
|
+
kwargs.each do |k, v|
|
74
|
+
next if args.key?(k)
|
75
|
+
|
76
|
+
args[:headers][k] = v
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
# rubocop:enable Metrics/ParameterLists
|
81
|
+
|
82
|
+
def deprecate_positional_args_message(method_name)
|
83
|
+
"The `#{method_name}` method should now receive keyword arguments " \
|
84
|
+
'rather than positional ones. Please update your publishers. This will ' \
|
85
|
+
'not be backwards compatible in the future.'
|
86
|
+
end
|
45
87
|
end
|
46
88
|
|
47
89
|
module ClassMethods
|
@@ -86,7 +128,7 @@ module Phobos
|
|
86
128
|
producer_store[:sync_producer] = nil
|
87
129
|
end
|
88
130
|
|
89
|
-
def publish(topic
|
131
|
+
def publish(topic:, payload:, key: nil, partition_key: nil, headers: nil)
|
90
132
|
publish_list([{ topic: topic, payload: payload, key: key,
|
91
133
|
partition_key: partition_key, headers: headers }])
|
92
134
|
end
|
@@ -109,7 +151,7 @@ module Phobos
|
|
109
151
|
producer_store[:async_producer]
|
110
152
|
end
|
111
153
|
|
112
|
-
def async_publish(topic
|
154
|
+
def async_publish(topic:, payload:, key: nil, partition_key: nil, headers: nil)
|
113
155
|
async_publish_list([{ topic: topic, payload: payload, key: key,
|
114
156
|
partition_key: partition_key, headers: headers }])
|
115
157
|
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.
|
4
|
+
version: 1.9.0.pre.beta1
|
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-
|
18
|
+
date: 2019-12-18 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: bundler
|