ears 0.7.0 → 0.8.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 +12 -0
- data/Gemfile.lock +4 -3
- data/README.md +4 -2
- data/lib/ears/middlewares/appsignal.rb +17 -5
- data/lib/ears/middlewares/json.rb +6 -2
- data/lib/ears/middlewares/max_retries.rb +2 -0
- 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: 03d47d36ce7244fbb253f4950fc280042f2ef3be7b6052d555ab2921fe930b9c
|
4
|
+
data.tar.gz: dddb56eb6b95f75b3689ee8f67e23834a6be29f984406264cdaea8c92ff177cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae5847aa47d96b2985df45b19df83e647e574e9a80217f300256bbeff784b9b80e03f58e5f93c24855b99c7f3042d0e8e51be4dd0855367478f402608fcba474
|
7
|
+
data.tar.gz: e2ac184be4bdc3da18ca3c2deaf0d54ad68e711efb1bec609af77167a0266becad721ba69d37e4aa5f162f7b6c31deeb7a20f12a60eaa12fc108b794f3a70a34
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.8.0 (2022-04-08)
|
4
|
+
|
5
|
+
- JSON middleware now requires an `on_error` callback in the options
|
6
|
+
|
7
|
+
## 0.7.2 (2022-02-24)
|
8
|
+
|
9
|
+
- change retry middleware to gracefully handle messages that do not have a header in their metadata
|
10
|
+
|
11
|
+
## 0.7.1 (2021-12-21)
|
12
|
+
|
13
|
+
- explicitly report Appsignal errors in middleware to make it more reliable
|
14
|
+
|
3
15
|
## 0.7.0 (2021-12-06)
|
4
16
|
|
5
17
|
- add options to create retry and error queues
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ears (0.
|
4
|
+
ears (0.8.0)
|
5
5
|
bunny
|
6
6
|
multi_json
|
7
7
|
|
@@ -20,7 +20,7 @@ GEM
|
|
20
20
|
ast (~> 2.4.1)
|
21
21
|
rainbow (3.0.0)
|
22
22
|
rake (13.0.6)
|
23
|
-
rbtree (0.4.
|
23
|
+
rbtree (0.4.5)
|
24
24
|
redcarpet (3.5.1)
|
25
25
|
regexp_parser (2.1.1)
|
26
26
|
rexml (3.2.5)
|
@@ -54,7 +54,7 @@ GEM
|
|
54
54
|
rubocop (~> 1.0)
|
55
55
|
rubocop-ast (>= 1.1.0)
|
56
56
|
ruby-progressbar (1.11.0)
|
57
|
-
set (1.0.
|
57
|
+
set (1.0.2)
|
58
58
|
sorted_set (1.0.3)
|
59
59
|
rbtree
|
60
60
|
set (~> 1.0)
|
@@ -63,6 +63,7 @@ GEM
|
|
63
63
|
|
64
64
|
PLATFORMS
|
65
65
|
arm64-darwin-20
|
66
|
+
arm64-darwin-21
|
66
67
|
x86_64-darwin-20
|
67
68
|
x86_64-linux
|
68
69
|
|
data/README.md
CHANGED
@@ -92,7 +92,9 @@ require 'ears/middlewares/json'
|
|
92
92
|
|
93
93
|
class MyConsumer < Ears::Consumer
|
94
94
|
# register the JSON middleware and don't symbolize keys (this can be omitted, the default is true)
|
95
|
-
use Ears::Middlewares::JSON,
|
95
|
+
use Ears::Middlewares::JSON,
|
96
|
+
on_error: Proc.new { :reject },
|
97
|
+
symbolize_keys: false
|
96
98
|
|
97
99
|
def work(delivery_info, metadata, payload)
|
98
100
|
return ack unless payload['data'].nil? # this now just works
|
@@ -165,7 +167,7 @@ my_queue =
|
|
165
167
|
queue('my_queue', durable: true, retry_queue: true, retry_delay: 5000)
|
166
168
|
```
|
167
169
|
|
168
|
-
This will automatically create a queue named `my_queue.retry` and use the arguments `x-dead-letter-exchange` and `x-dead-letter-routing-key` to route rejected messages to it. When routed to the retry queue, messages will wait there for the number of milliseconds specified in `retry_delay`, after which they will be redelivered to the original queue.
|
170
|
+
This will automatically create a queue named `my_queue.retry` and use the arguments `x-dead-letter-exchange` and `x-dead-letter-routing-key` to route rejected messages to it. When routed to the retry queue, messages will wait there for the number of milliseconds specified in `retry_delay`, after which they will be redelivered to the original queue. **Note that this will not automatically catch unhandled errors. You still have to catch any errors yourself and reject your message manually for the retry mechanism to work.**
|
169
171
|
|
170
172
|
This will happen indefinitely, so if you want to bail out of this cycle at some point, it is best to use the `error_queue` option to create an error queue and then use the `MaxRetries` middleware to route messages to this error queue after a certain amount of retries.
|
171
173
|
|
@@ -14,17 +14,29 @@ module Ears
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def call(delivery_info, metadata, payload, app)
|
17
|
+
start_transaction do
|
18
|
+
begin
|
19
|
+
app.call(delivery_info, metadata, payload)
|
20
|
+
rescue => e
|
21
|
+
::Appsignal.set_error(e)
|
22
|
+
raise
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
attr_reader :transaction_name, :class_name
|
30
|
+
|
31
|
+
def start_transaction(&block)
|
17
32
|
::Appsignal.monitor_transaction(
|
18
33
|
transaction_name,
|
19
34
|
class: class_name,
|
20
35
|
method: 'work',
|
21
36
|
queue_start: Time.now.utc,
|
22
|
-
|
37
|
+
&block
|
38
|
+
)
|
23
39
|
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
attr_reader :transaction_name, :class_name
|
28
40
|
end
|
29
41
|
end
|
30
42
|
end
|
@@ -6,20 +6,24 @@ module Ears
|
|
6
6
|
# A middleware that automatically parses your JSON payload.
|
7
7
|
class JSON < Middleware
|
8
8
|
# @param [Hash] opts The options for the middleware.
|
9
|
-
# @option opts [
|
9
|
+
# @option opts [Proc] :on_error A Proc to be called when an error occurs during processing
|
10
|
+
# @option opts [Boolean] :symbolize_keys (true) Whether to symbolize the keys of your payload.
|
10
11
|
def initialize(opts = {})
|
11
12
|
super()
|
13
|
+
@on_error = opts.fetch(:on_error)
|
12
14
|
@symbolize_keys = opts.fetch(:symbolize_keys, true)
|
13
15
|
end
|
14
16
|
|
15
17
|
def call(delivery_info, metadata, payload, app)
|
16
18
|
parsed_payload = MultiJson.load(payload, symbolize_keys: symbolize_keys)
|
17
19
|
app.call(delivery_info, metadata, parsed_payload)
|
20
|
+
rescue => e
|
21
|
+
on_error.call(e)
|
18
22
|
end
|
19
23
|
|
20
24
|
private
|
21
25
|
|
22
|
-
attr_reader :symbolize_keys
|
26
|
+
attr_reader :symbolize_keys, :on_error
|
23
27
|
end
|
24
28
|
end
|
25
29
|
end
|
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.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mario Mainz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|