message-driver 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Guardfile +1 -0
- data/README.md +1 -1
- data/features/middleware/middleware_error_handling.feature +120 -0
- data/lib/message_driver/adapters/bunny_adapter.rb +8 -6
- data/lib/message_driver/middleware/middleware_stack.rb +1 -1
- data/lib/message_driver/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1296071efa2a7b9f589eddcd94d99847f515ad16
|
4
|
+
data.tar.gz: 9b0a163a287824a8f2928dd13d5083b7a97b3245
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f344fef0e415eb76d0d54572390ec1311fdb1165ea9126fb59de69f70a7e324cb94b852a11b138e489b7f05cceea4132480f63ecea115b958acf69c218c9c570
|
7
|
+
data.tar.gz: 0da3bc34be7f8c00c01b45cda0f9acf152bdf33640ddd947254538c58dbbb5c7a163edfda4579759430594a787754fc90dca54c5b9780d16f0321b7cce46414b
|
data/CHANGELOG.md
CHANGED
data/Guardfile
CHANGED
@@ -45,6 +45,7 @@ group :tests_and_checks, halt_on_failure: true do
|
|
45
45
|
group 'features' do
|
46
46
|
guard('cucumber',
|
47
47
|
all_on_start: false,
|
48
|
+
all_after_pass: false,
|
48
49
|
cmd: "bundle exec cucumber --no-profile --color --strict --tag @all_adapters,@#{BrokerConfig.current_adapter} --tag ~@wip",
|
49
50
|
cmd_additional_args: '--format pretty --tag ~@slow',
|
50
51
|
run_all: {
|
data/README.md
CHANGED
@@ -0,0 +1,120 @@
|
|
1
|
+
@bunny
|
2
|
+
Feature: Middleware Error Handling
|
3
|
+
|
4
|
+
If a middleware raises an error, we need to ensure it is handled properly.
|
5
|
+
|
6
|
+
Background:
|
7
|
+
Given I am connected to the broker
|
8
|
+
And I have a destination :middleware_queue with no messages on it
|
9
|
+
And I have a middleware class
|
10
|
+
"""ruby
|
11
|
+
class ErrorMiddleware < MessageDriver::Middleware::Base
|
12
|
+
# def on_publish(body, headers, properties)
|
13
|
+
# [body, headers, properties]
|
14
|
+
# end
|
15
|
+
|
16
|
+
def on_consume(body, headers, properties)
|
17
|
+
if body.start_with? 'error'
|
18
|
+
raise "error trying to consume! #{body}"
|
19
|
+
else
|
20
|
+
[body, headers, properties]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
"""
|
25
|
+
And I append middleware "ErrorMiddleware" to :middleware_queue
|
26
|
+
And I have a destination :dest_queue with no messages on it
|
27
|
+
|
28
|
+
@in_memory
|
29
|
+
Scenario: Publishing a message
|
30
|
+
Given I have a middleware class
|
31
|
+
"""ruby
|
32
|
+
class PublishErrorMiddleware < MessageDriver::Middleware::Base
|
33
|
+
def on_publish(body, headers, properties)
|
34
|
+
raise 'error trying to publish!'
|
35
|
+
end
|
36
|
+
|
37
|
+
def on_consume(body, headers, properties)
|
38
|
+
[body, headers, properties]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
"""
|
42
|
+
And I append middleware "PublishErrorMiddleware" to :middleware_queue
|
43
|
+
|
44
|
+
When I execute the following code
|
45
|
+
"""ruby
|
46
|
+
MessageDriver::Client.publish(:middleware_queue, 'middleware error test')
|
47
|
+
"""
|
48
|
+
Then I expect it to raise "error trying to publish!"
|
49
|
+
And I expect to find no message on :middleware_queue
|
50
|
+
|
51
|
+
|
52
|
+
Scenario: Consuming a message with an auto-ack consumer
|
53
|
+
Given I create a subscription
|
54
|
+
"""ruby
|
55
|
+
MessageDriver::Client.subscribe_with(:middleware_queue) do |message|
|
56
|
+
MessageDriver::Client.publish(:dest_queue, message.body)
|
57
|
+
end
|
58
|
+
"""
|
59
|
+
|
60
|
+
When I send the following message to :middleware_queue
|
61
|
+
| body |
|
62
|
+
| Test Message 1 |
|
63
|
+
| error message |
|
64
|
+
| Test Message 2 |
|
65
|
+
And I let the subscription process
|
66
|
+
|
67
|
+
Then I expect to find the following 2 messages on :dest_queue
|
68
|
+
| body |
|
69
|
+
| Test Message 1 |
|
70
|
+
| Test Message 2 |
|
71
|
+
And I expect to find the following message on :middleware_queue
|
72
|
+
| body |
|
73
|
+
| error message |
|
74
|
+
|
75
|
+
Scenario: Consuming with a manual ack consumer
|
76
|
+
Given I create a subscription
|
77
|
+
"""ruby
|
78
|
+
MessageDriver::Client.subscribe_with(:middleware_queue, ack: :manual) do |message|
|
79
|
+
MessageDriver::Client.publish(:dest_queue, message.body)
|
80
|
+
message.ack
|
81
|
+
end
|
82
|
+
"""
|
83
|
+
|
84
|
+
When I send the following message to :middleware_queue
|
85
|
+
| body |
|
86
|
+
| Test Message 1 |
|
87
|
+
| error message |
|
88
|
+
| Test Message 2 |
|
89
|
+
And I let the subscription process
|
90
|
+
|
91
|
+
Then I expect to find the following 2 messages on :dest_queue
|
92
|
+
| body |
|
93
|
+
| Test Message 1 |
|
94
|
+
| Test Message 2 |
|
95
|
+
And I expect to find the following message on :middleware_queue
|
96
|
+
| body |
|
97
|
+
| error message |
|
98
|
+
|
99
|
+
Scenario: Consuming with a transactional ack consumer
|
100
|
+
Given I create a subscription
|
101
|
+
"""ruby
|
102
|
+
MessageDriver::Client.subscribe_with(:middleware_queue, ack: :transactional) do |message|
|
103
|
+
MessageDriver::Client.publish(:dest_queue, message.body)
|
104
|
+
end
|
105
|
+
"""
|
106
|
+
|
107
|
+
When I send the following message to :middleware_queue
|
108
|
+
| body |
|
109
|
+
| Test Message 1 |
|
110
|
+
| error message |
|
111
|
+
| Test Message 2 |
|
112
|
+
And I let the subscription process
|
113
|
+
|
114
|
+
Then I expect to find the following 2 messages on :dest_queue
|
115
|
+
| body |
|
116
|
+
| Test Message 1 |
|
117
|
+
| Test Message 2 |
|
118
|
+
And I expect to find the following message on :middleware_queue
|
119
|
+
| body |
|
120
|
+
| error message |
|
@@ -181,13 +181,14 @@ module MessageDriver
|
|
181
181
|
include Logging
|
182
182
|
|
183
183
|
attr_accessor :subscription
|
184
|
-
def_delegators :subscription, :adapter, :sub_ctx, :consumer, :error_handler, :options
|
184
|
+
def_delegators :subscription, :adapter, :sub_ctx, :consumer, :error_handler, :options, :destination
|
185
185
|
|
186
186
|
def initialize(subscription)
|
187
187
|
@subscription = subscription
|
188
188
|
end
|
189
189
|
|
190
|
-
def call(
|
190
|
+
def call(*message_args)
|
191
|
+
message = sub_ctx.args_to_message(*message_args, destination)
|
191
192
|
consumer.call(message)
|
192
193
|
rescue => e
|
193
194
|
error_handler.call(e, message) unless error_handler.nil?
|
@@ -213,7 +214,8 @@ module MessageDriver
|
|
213
214
|
end
|
214
215
|
|
215
216
|
class AutoAckHandler < MessageHandler
|
216
|
-
def call(
|
217
|
+
def call(*message_args)
|
218
|
+
message = sub_ctx.args_to_message(*message_args, destination)
|
217
219
|
consumer.call(message)
|
218
220
|
sub_ctx.ack_message(message)
|
219
221
|
rescue => e
|
@@ -223,7 +225,8 @@ module MessageDriver
|
|
223
225
|
end
|
224
226
|
|
225
227
|
class TransactionalAckHandler < MessageHandler
|
226
|
-
def call(
|
228
|
+
def call(*message_args)
|
229
|
+
message = sub_ctx.args_to_message(*message_args, destination)
|
227
230
|
adapter.broker.client.with_message_transaction do
|
228
231
|
consumer.call(message)
|
229
232
|
sub_ctx.ack_message(message)
|
@@ -241,8 +244,7 @@ module MessageDriver
|
|
241
244
|
sub_opts = options.merge(adapter.ack_key => true)
|
242
245
|
@bunny_consumer = queue.subscribe(sub_opts) do |delivery_info, properties, payload|
|
243
246
|
adapter.broker.client.with_adapter_context(@sub_ctx) do
|
244
|
-
|
245
|
-
@message_handler.call(message)
|
247
|
+
@message_handler.call(delivery_info, properties, payload)
|
246
248
|
end
|
247
249
|
end
|
248
250
|
end
|
@@ -33,7 +33,7 @@ module MessageDriver
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def on_consume(body, headers, properties)
|
36
|
-
@middlewares.
|
36
|
+
@middlewares.reverse_each.reduce([body, headers, properties]) do |args, middleware|
|
37
37
|
middleware.on_consume(*args)
|
38
38
|
end
|
39
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: message-driver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Campbell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -116,6 +116,7 @@ files:
|
|
116
116
|
- features/message_consumers/subscribe_with_a_block.feature
|
117
117
|
- features/message_consumers/transactional_ack_consumers.feature
|
118
118
|
- features/middleware/middleware_basics.feature
|
119
|
+
- features/middleware/middleware_error_handling.feature
|
119
120
|
- features/middleware/middleware_ordering.feature
|
120
121
|
- features/middleware/middleware_parameters.feature
|
121
122
|
- features/middleware/middleware_with_blocks.feature
|
@@ -236,6 +237,7 @@ test_files:
|
|
236
237
|
- features/message_consumers/subscribe_with_a_block.feature
|
237
238
|
- features/message_consumers/transactional_ack_consumers.feature
|
238
239
|
- features/middleware/middleware_basics.feature
|
240
|
+
- features/middleware/middleware_error_handling.feature
|
239
241
|
- features/middleware/middleware_ordering.feature
|
240
242
|
- features/middleware/middleware_parameters.feature
|
241
243
|
- features/middleware/middleware_with_blocks.feature
|