phobos 1.8.3.pre.beta2 → 1.9.0.pre.beta1

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
  SHA256:
3
- metadata.gz: 0d9c3d6d826d8865116eeeef7183e1d3eb60862d4673fb10c0464577707e1a8a
4
- data.tar.gz: 7317cdfb2c8516cfa837f52c41d14181987ccdd12698eccfb8119def24c24ab1
3
+ metadata.gz: 9ac51b2a5d3cdaa995dc2f8dfca3d8597c225c0b311724655712bb1ba7060991
4
+ data.tar.gz: d58bf202dced7bf24c483b0cd2067e4e13e2a43e8f1cfa756377ccf1cf4861dc
5
5
  SHA512:
6
- metadata.gz: 8f4eb5b010f7c628db69ddbf4c5cc4237d1afff4f8a42b462e9e47cf835a2bbf2950c827865640bb3456009a7fcdd2b900df3d1d758206e82ddb774ffef5c202
7
- data.tar.gz: 5b3a4b2ac5755a296097c52ded7e5ead4fc866250ff24c16ca75e620dd056c315dbeba1055fee1c4f509d88619b1bb0aaea7c8b6cf61861ac72ed1fab6aa1ad7
6
+ metadata.gz: 4b41e84f671b6f59d94bced995a491818468b1932fe22309e55bff1236d5f165c624d65647bc24ce054f5ab41e8ed20a53ffdb04ab21d755a3fa46cc52e9ba24
7
+ data.tar.gz: 69651f14500c3c0126b55429f0c5fd8bc2118845a6eac07147cd4c7cd87aa12d7f101a79f250cd428747c322ad469121af8a10fe94af3bc1f5fa67c70d0666a6
@@ -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 = nil, partition_key = nil, headers = nil)
293
+ def publish(topic: topic, payload: payload, key: nil, partition_key: nil, headers: nil)
294
294
  ```
295
295
 
296
- To produce messages with headers, 5 arguments will have to be passed to `publish`:
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', nil, { header_1: 'value 1' })
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
  ```
@@ -45,7 +45,7 @@ Thread.new do
45
45
  #
46
46
  MyProducer
47
47
  .producer
48
- .async_publish(TOPIC, payload, key)
48
+ .async_publish(topic: TOPIC, payload: payload, key: key)
49
49
 
50
50
  puts "produced #{key}, total: #{total}"
51
51
 
@@ -78,7 +78,8 @@ module Phobos
78
78
  end
79
79
 
80
80
  def deprecate(message)
81
- warn "DEPRECATION WARNING: #{message} #{Kernel.caller.first}"
81
+ location = caller.find { |line| line !~ %r{/phobos/} }
82
+ warn "DEPRECATION WARNING: #{message}: #{location}"
82
83
  end
83
84
 
84
85
  # :nodoc:
@@ -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
- 'please update your consumer. This will not be backwards compatible in the future.')
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
- 'please update your consumer. This will not be backwards compatible in the future.')
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
@@ -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(topic, payload, key = nil, partition_key = nil, headers = nil)
19
- class_producer.publish(topic, payload, key, partition_key, headers)
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(topic, payload, key = nil, partition_key = nil, headers = nil)
23
- class_producer.async_publish(topic, payload, key, partition_key, headers)
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, payload, key = nil, partition_key = nil, headers = nil)
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, payload, key = nil, partition_key = nil, headers = nil)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Phobos
4
- VERSION = '1.8.3-beta2'
4
+ VERSION = '1.9.0-beta1'
5
5
  end
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.beta2
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-11-15 00:00:00.000000000 Z
18
+ date: 2019-12-18 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: bundler