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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d3bcb04e7ce78a6c1fa187b2c3a4c1bdecc74506
4
- data.tar.gz: 87bde205475a8f149eb6d08b0520b24826316189
3
+ metadata.gz: 1296071efa2a7b9f589eddcd94d99847f515ad16
4
+ data.tar.gz: 9b0a163a287824a8f2928dd13d5083b7a97b3245
5
5
  SHA512:
6
- metadata.gz: e9f602d1836c47357d30d76c7c34e1e75a5ebad910f84fa6871960d4fdefc9913c30d612ae9c4b3d52b84368ef8046164d1bc0a922f62f4f8e965d5d8fabb0a2
7
- data.tar.gz: cf87a47b64e7fd438c515c4abb5891f6f6c803190d2fa3e7b8e89f3722f20db0be9ef89dd5c14ffc8c85a4c0896945ae4dfcc9ebce1b84e2ea9e0321b04829dd
6
+ metadata.gz: f344fef0e415eb76d0d54572390ec1311fdb1165ea9126fb59de69f70a7e324cb94b852a11b138e489b7f05cceea4132480f63ecea115b958acf69c218c9c570
7
+ data.tar.gz: 0da3bc34be7f8c00c01b45cda0f9acf152bdf33640ddd947254538c58dbbb5c7a163edfda4579759430594a787754fc90dca54c5b9780d16f0321b7cce46414b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.1 - 2017-04-10
4
+
5
+ * Move middleware processing for consumers inside the message handler so error in middleware are correctly handled - Fixes #35
6
+
3
7
  ## 0.7.0 - 2016-12-19
4
8
 
5
9
  * update test gems
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
@@ -1,4 +1,4 @@
1
- # Message::Driver
1
+ # MessageDriver
2
2
 
3
3
  Easy message queues for ruby
4
4
 
@@ -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(message)
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(message)
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(message)
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
- message = @sub_ctx.args_to_message(delivery_info, properties, payload, destination)
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.reverse.reduce([body, headers, properties]) do |args, middleware|
36
+ @middlewares.reverse_each.reduce([body, headers, properties]) do |args, middleware|
37
37
  middleware.on_consume(*args)
38
38
  end
39
39
  end
@@ -1,4 +1,4 @@
1
1
  module MessageDriver
2
2
  # @return [String] version of the library
3
- VERSION = '0.7.0'.freeze
3
+ VERSION = '0.7.1'.freeze
4
4
  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.0
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: 2016-12-19 00:00:00.000000000 Z
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