ears 0.12.0 → 0.13.0

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: 2b5be9543cc8c9a75eb078b181786cd85864515064cce8ddb130647e53611700
4
- data.tar.gz: 48b47f63a7e90c9e149cb008c6a34c35b9d8f4b8133f43c558906fe1fb5398ec
3
+ metadata.gz: ba8ffc55e16ec7c7f0b7e3327b25aaf287feba34cc527d93d40d5b59bb4a1976
4
+ data.tar.gz: cacc33604f6299450735d16a376d583ffea86f27cc04e6108eab92473ae2ac50
5
5
  SHA512:
6
- metadata.gz: c0e1a9620e0b167921c80e54df06f52fbfff47ea1023d07f8533f888e81443c5583addf46fa3129c32944b534da1595f7b23bff93e457575e72502b1fb7e98c9
7
- data.tar.gz: 119f76252574d361b0d339e427203dbd952045afda5d329e6a327d48f5cabdcacb752f04e4ebe4398d86d55ac26314d678f61d925bf79e81d9e11f67b3f4240f
6
+ metadata.gz: aa791974d982def87dfff26bc03819e5cd9c12d25440a055a3c9ce3bb5ebf8c6b36d00f31f93b3b37d5f0702ce4d5831e47f86e24abea9efde01b6d40e8f9482
7
+ data.tar.gz: df472e7514f6308e4436f0e475ea0dbcbf1e5e3219d87a3bc7adddb9ea74ee198088f9d565db61925cad3865f24fa25d6d1ff9db7b85bc84122fb0d934c1dbac
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.13.0 (2023-11-07)
4
+
5
+ - Allow adding multiple routing keys to the consumer configuration, configure method within consumer will only accept `routing_keys` array instead of `routing_key` string
6
+
3
7
  ## 0.12.0 (2023-10-26)
4
8
 
5
9
  - add new interface to setup consumers including their exchange, queue and binding the queue to the exchange via routing key via `Ears.setup_consumers` and `configure(queue:, exchange:,routing_key:, ...)` for Ears::Consumers subclasses
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ears (0.12.0)
4
+ ears (0.13.0)
5
5
  bunny (~> 2.22.0)
6
6
  multi_json
7
7
 
data/README.md CHANGED
@@ -39,7 +39,39 @@ end
39
39
 
40
40
  _Note_: `connection_name` is a mandatory setting!
41
41
 
42
- Next, define your exchanges, queues, and consumers by calling `Ears.setup`.
42
+ Next, you can define your exchanges, queues, and consumers in 2 ways:
43
+
44
+ #### 1. consumer specific configuration method (recommended)
45
+
46
+ 1. Pass your consumer classes to `Ears.setup`:
47
+
48
+ ```ruby
49
+ Ears.setup do
50
+ Ears.setup_consumers(Consumer1, Consumer2, ...)
51
+ end
52
+ ```
53
+
54
+ 2. Implement your consumers by subclassing `Ears::Consumer`. and call the configure method.
55
+
56
+ ```ruby
57
+ class Consumer1 < Ears::Consumer
58
+ configure(
59
+ queue: 'queue_name',
60
+ exchange: 'exchange',
61
+ routing_keys: %w[routing_key1 routing_key2],
62
+ retry_queue: true, # optional configuration, defaults to false, Adds a retry queue
63
+ error_queue: true, # optional configuration, defaults to false, Adds an error queue
64
+ )
65
+ def work(delivery_info, metadata, payload)
66
+ message = JSON.parse(payload)
67
+ do_stuff(message)
68
+
69
+ ack
70
+ end
71
+ end
72
+ ```
73
+
74
+ #### 2. Generic configuration method
43
75
 
44
76
  ```ruby
45
77
  Ears.setup do
@@ -57,7 +89,7 @@ Ears.setup do
57
89
  end
58
90
  ```
59
91
 
60
- Finally, you need to implement `MyConsumer` by subclassing `Ears::Consumer`.
92
+ Finally, you need to implement `MyConsumer` by subclassing `Ears::Consumer`. and call the configure method.
61
93
 
62
94
  ```ruby
63
95
  class MyConsumer < Ears::Consumer
@@ -70,7 +102,9 @@ class MyConsumer < Ears::Consumer
70
102
  end
71
103
  ```
72
104
 
73
- And, do not forget to run it. Be prepared that unhandled errors will be reraised. So, take care of cleanup work.
105
+ ### Run your consumers
106
+
107
+ Note: Be prepared that unhandled errors will be reraised. So, take care of cleanup work.
74
108
 
75
109
  ```ruby
76
110
  begin
@@ -165,7 +199,24 @@ end
165
199
 
166
200
  ### Implementing a retrying queue
167
201
 
168
- Sometimes you want to automatically retry processing a message, in case it just failed due to temporary problems. In that case, you can set the `retry_queue` and `retry_delay` parameters when creating the queue.
202
+ Sometimes you want to automatically retry processing a message, in case it just failed due to temporary problems. In that case, you can set the `retry_queue` and `retry_delay` parameters when creating the queue OR pass it to the configure method in your consumer.
203
+
204
+ ```ruby
205
+ class MyConsumer < Ears::Consumer
206
+ configure(
207
+ queue: 'queue_name',
208
+ exchange: 'exchange',
209
+ routing_keys: %w[routing_key1 routing_key2],
210
+ retry_queue: true,
211
+ )
212
+ def work(delivery_info, metadata, payload)
213
+ message = JSON.parse(payload)
214
+ do_stuff(message)
215
+
216
+ ack
217
+ end
218
+ end
219
+ ```
169
220
 
170
221
  ```ruby
171
222
  my_queue =
@@ -178,7 +229,24 @@ This will happen indefinitely, so if you want to bail out of this cycle at some
178
229
 
179
230
  ### Implementing an error queue
180
231
 
181
- You can set the `error_queue` parameter to automatically create an error queue.
232
+ You can set the `error_queue` parameter to automatically create an error queue, or add it to the configure method in your consumer.
233
+
234
+ ```ruby
235
+ class MyConsumer < Ears::Consumer
236
+ configure(
237
+ queue: 'queue_name',
238
+ exchange: 'exchange',
239
+ routing_keys: %w[routing_key1 routing_key2],
240
+ error_queue: true,
241
+ )
242
+ def work(delivery_info, metadata, payload)
243
+ message = JSON.parse(payload)
244
+ do_stuff(message)
245
+
246
+ ack
247
+ end
248
+ end
249
+ ```
182
250
 
183
251
  ```ruby
184
252
  my_queue =
data/lib/ears/consumer.rb CHANGED
@@ -33,17 +33,18 @@ module Ears
33
33
  # @param [Hash] opts The options to configure the consumer with.
34
34
  # @option opts [String] :queue The name of the queue to consume from.
35
35
  # @option opts [String] :exchange The name of the exchange the queue should be bound to.
36
- # @option opts [String] :routing_key The routing key used the queue binding.
36
+ # @option opts [Array] :routing_keys The routing keys used for the queue binding.
37
37
  # @option opts [Boolean] :durable_queue (true) Whether the queue should be durable.
38
38
  # @option opts [Boolean] :retry_queue (false) Whether a retry queue should be provided.
39
39
  # @option opts [Integer] :retry_delay (5000) The delay in milliseconds before retrying a message.
40
40
  # @option opts [Boolean] :error_queue (false) Whether an error queue should be provided.
41
41
  # @option opts [Boolean] :durable_exchange (true) Whether the exchange should be durable.
42
42
  # @option opts [Symbol] :exchange_type (:topic) The type of exchange to use.
43
+ # @option opts [Integer] :threads (1) The number of threads to use for this consumer.
43
44
  def self.configure(opts = {})
44
45
  self.queue = opts.fetch(:queue)
45
46
  self.exchange = opts.fetch(:exchange)
46
- self.routing_key = opts.fetch(:routing_key)
47
+ self.routing_keys = opts.fetch(:routing_keys)
47
48
  self.queue_options = queue_options_from(opts: opts)
48
49
  self.durable_exchange = opts.fetch(:durable_exchange, true)
49
50
  self.exchange_type = opts.fetch(:exchange_type, :topic)
@@ -127,7 +128,7 @@ module Ears
127
128
  class << self
128
129
  attr_reader :queue,
129
130
  :exchange,
130
- :routing_key,
131
+ :routing_keys,
131
132
  :queue_options,
132
133
  :durable_exchange,
133
134
  :exchange_type
@@ -145,7 +146,7 @@ module Ears
145
146
 
146
147
  attr_writer :queue,
147
148
  :exchange,
148
- :routing_key,
149
+ :routing_keys,
149
150
  :queue_options,
150
151
  :durable_exchange,
151
152
  :exchange_type
data/lib/ears/setup.rb CHANGED
@@ -76,10 +76,16 @@ module Ears
76
76
  )
77
77
  configured_queue =
78
78
  queue(consumer_class.queue, consumer_class.queue_options)
79
- configured_queue.bind(exchange, routing_key: consumer_class.routing_key)
79
+ bind_queue_to_routing_keys(consumer_class, exchange, configured_queue)
80
80
  consumer(configured_queue, consumer_class)
81
81
  end
82
82
 
83
+ def bind_queue_to_routing_keys(consumer_class, exchange, configured_queue)
84
+ consumer_class.routing_keys.each do |routing_key|
85
+ configured_queue.bind(exchange, routing_key: routing_key)
86
+ end
87
+ end
88
+
83
89
  def queue_options(bunny_opts, retry_arguments)
84
90
  return bunny_opts unless retry_arguments
85
91
 
data/lib/ears/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ears
2
- VERSION = '0.12.0'
2
+ VERSION = '0.13.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ears
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - InVision AG
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-26 00:00:00.000000000 Z
11
+ date: 2023-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny