ears 0.12.0 → 0.13.0
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 +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +73 -5
- data/lib/ears/consumer.rb +5 -4
- data/lib/ears/setup.rb +7 -1
- data/lib/ears/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: ba8ffc55e16ec7c7f0b7e3327b25aaf287feba34cc527d93d40d5b59bb4a1976
|
4
|
+
data.tar.gz: cacc33604f6299450735d16a376d583ffea86f27cc04e6108eab92473ae2ac50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
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
|
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
|
-
|
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 [
|
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.
|
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
|
-
:
|
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
|
-
:
|
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
|
-
|
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
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.
|
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-
|
11
|
+
date: 2023-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|