action_subscriber 5.1.0.pre-java → 5.1.1-java

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
- SHA256:
3
- metadata.gz: 8c6a4db4087f78e1c16c2ad21e25d45c7e062d1767e1e6c4f2d29518e93bdfa2
4
- data.tar.gz: 3d5819a42753bb06ee490e66293565fb1e636d547735fc7d4bcf06ce6c88502b
2
+ SHA1:
3
+ metadata.gz: 9d12c0bd459bf3cf6fe2b0d44f36aec3f8eb4c5f
4
+ data.tar.gz: 8433d4975c8761882b911de975eb7109bb1b93f5
5
5
  SHA512:
6
- metadata.gz: e093f13797fdf8ca5afba83a20bd575b5fe791692e36ebc0bb9c33a8a32742ecaf6a352a5ad1273818557d497bed790219c048afdc90f3a2ef2eb51ec5094030
7
- data.tar.gz: 3dec8b008760311b7d7959d5b2805bd16b8dae8c05ad67e8f27f6abc39ae5975dfcbfe2381bf35d9d69452afc492f138a7d1e7c5b1c14ef1d8b47a0e32d337db
6
+ metadata.gz: c3a82ecf93d01ffdaced3b78158f395fafb19cfb80df7b80f944078b881780f2e3270b638016aff13ebabeadbe5c415b61e9c0c8edbf847f0fcd4908582fa200
7
+ data.tar.gz: fae306be8aae1ebbc5a2b29589d7ff6f7708b66a04f8960eb32d9aeca8f292a54de67618947cfaa8d41d53308801941245ca79aee2b7f25c5e148e4d8d9a8892
@@ -46,14 +46,21 @@ module ActionSubscriber
46
46
 
47
47
  def acknowledge
48
48
  fail ::RuntimeError, "you can't acknowledge messages under the polling API" unless @channel
49
+ return true if @has_been_acked
49
50
  acknowledge_multiple_messages = false
50
51
  @has_been_acked = true
51
52
  @channel.ack(@delivery_tag, acknowledge_multiple_messages)
52
53
  true
53
54
  end
54
55
 
56
+ def channel_open?
57
+ return false unless @channel
58
+ @channel.open?
59
+ end
60
+
55
61
  def nack
56
62
  fail ::RuntimeError, "you can't acknowledge messages under the polling API" unless @channel
63
+ return true if @has_been_nacked
57
64
  nack_multiple_messages = false
58
65
  requeue_message = true
59
66
  @has_been_nacked = true
@@ -63,6 +70,7 @@ module ActionSubscriber
63
70
 
64
71
  def reject
65
72
  fail ::RuntimeError, "you can't acknowledge messages under the polling API" unless @channel
73
+ return true if @has_been_rejected
66
74
  requeue_message = true
67
75
  @has_been_rejected = true
68
76
  @channel.reject(@delivery_tag, requeue_message)
@@ -70,15 +78,15 @@ module ActionSubscriber
70
78
  end
71
79
 
72
80
  def safe_acknowledge
73
- acknowledge if uses_acknowledgements? && @channel && !has_used_delivery_tag?
81
+ acknowledge if uses_acknowledgements? && channel_open? && !has_used_delivery_tag?
74
82
  end
75
83
 
76
84
  def safe_nack
77
- nack if uses_acknowledgements? && @channel && !has_used_delivery_tag?
85
+ nack if uses_acknowledgements? && channel_open? && !has_used_delivery_tag?
78
86
  end
79
87
 
80
88
  def safe_reject
81
- reject if uses_acknowledgements? && @channel && !has_used_delivery_tag?
89
+ reject if uses_acknowledgements? && channel_open? && !has_used_delivery_tag?
82
90
  end
83
91
 
84
92
  def to_hash
@@ -22,7 +22,14 @@ module ActionSubscriber
22
22
  logger.error { "ActionSubscriber error handler raised error, but should never raise. Error: #{inner_error}" }
23
23
  end
24
24
  ensure
25
- env.safe_nack # Make sure we attempt to `nack` a message that did not get processed if something fails
25
+ # This second rescue is a little extreme, but we need to be very cautious here to avoid errors
26
+ # being sent back to bunny or march_hare land.
27
+ begin
28
+ # Make sure we attempt to `nack` a message that did not get processed if something fails
29
+ env.safe_nack
30
+ rescue Exception => inner_error
31
+ logger.error { "ActionSubscriber error handler raised error while nack-ing message. Error: #{inner_error}" }
32
+ end
26
33
  end
27
34
  end
28
35
  end
@@ -3,10 +3,18 @@ require 'rspec/core'
3
3
  module ActionSubscriber
4
4
  module RSpec
5
5
  class FakeChannel # A class that quacks like a RabbitMQ Channel
6
+ def initialize(opts = {})
7
+ @open = opts.fetch(:open, true)
8
+ end
9
+
6
10
  def ack(delivery_tag, acknowledge_multiple)
7
11
  true
8
12
  end
9
13
 
14
+ def open?
15
+ @open
16
+ end
17
+
10
18
  def nack(delivery_tag, acknowledge_multiple, requeue_message)
11
19
  true
12
20
  end
@@ -76,9 +84,10 @@ end
76
84
  shared_context 'action subscriber middleware env' do
77
85
  let(:app) { Proc.new { |inner_env| inner_env } }
78
86
  let(:env) { ActionSubscriber::Middleware::Env.new(UserSubscriber, 'encoded payload', message_properties) }
87
+ let(:channel) { ::ActionSubscriber::RSpec::FakeChannel.new }
79
88
  let(:message_properties) {{
80
89
  :action => :created,
81
- :channel => ::ActionSubscriber::RSpec::FakeChannel.new,
90
+ :channel => channel,
82
91
  :content_type => "text/plain",
83
92
  :delivery_tag => "XYZ",
84
93
  :exchange => "events",
@@ -1,3 +1,3 @@
1
1
  module ActionSubscriber
2
- VERSION = "5.1.0.pre"
2
+ VERSION = "5.1.1"
3
3
  end
@@ -9,6 +9,26 @@ describe ActionSubscriber::Middleware::ErrorHandler do
9
9
 
10
10
  let(:load_error) { ::LoadError.new("Boom!") }
11
11
  let(:runtime_error) { ::RuntimeError.new("Boom!") }
12
+ let(:message_properties) {{
13
+ :action => :created,
14
+ :channel => channel,
15
+ :content_type => "text/plain",
16
+ :delivery_tag => "XYZ",
17
+ :exchange => "events",
18
+ :headers => {},
19
+ :message_id => "MSG-123",
20
+ :routing_key => "amigo.user.created",
21
+ :queue => "test.amigo.user.created",
22
+ :uses_acknowledgements => true,
23
+ }}
24
+
25
+ it "calls safe_nack after successful execution" do
26
+ expect(env).to receive(:safe_nack).and_call_original
27
+ expect(env).to_not receive(:nack)
28
+
29
+ env.acknowledge
30
+ subject.call(env)
31
+ end
12
32
 
13
33
  context "when an exception occurs" do
14
34
  context "LoadError" do
@@ -23,18 +43,31 @@ describe ActionSubscriber::Middleware::ErrorHandler do
23
43
 
24
44
  context "RuntimError" do
25
45
  before { allow(app).to receive(:call).and_raise(runtime_error) }
46
+
26
47
  it "calls the exception handler with a RuntimeError" do
27
48
  handler = ::ActionSubscriber.configuration.error_handler
28
49
  expect(handler).to receive(:call).with(runtime_error, env.to_h)
29
50
 
30
51
  subject.call(env)
31
52
  end
32
- end
33
53
 
34
- it "calls safe_nack after execution" do
35
- expect(env).to receive(:safe_nack)
54
+ it "calls safe_nack after execution" do
55
+ expect(env).to receive(:safe_nack).and_call_original
56
+ expect(env).to receive(:nack)
36
57
 
37
- subject.call(env)
58
+ subject.call(env)
59
+ end
60
+
61
+ context "when the channel is closed without an ack" do
62
+ let(:channel) { ::ActionSubscriber::RSpec::FakeChannel.new(:open => false) }
63
+
64
+ it "calls safe_nack after execution" do
65
+ expect(env).to receive(:safe_nack).and_call_original
66
+ expect(env).to_not receive(:nack)
67
+
68
+ subject.call(env)
69
+ end
70
+ end
38
71
  end
39
72
  end
40
73
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_subscriber
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.0.pre
4
+ version: 5.1.1
5
5
  platform: java
6
6
  authors:
7
7
  - Brian Stien
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2018-01-16 00:00:00.000000000 Z
15
+ date: 2018-03-06 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  requirement: !ruby/object:Gem::Requirement
@@ -292,12 +292,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
292
292
  version: '0'
293
293
  required_rubygems_version: !ruby/object:Gem::Requirement
294
294
  requirements:
295
- - - ">"
295
+ - - ">="
296
296
  - !ruby/object:Gem::Version
297
- version: 1.3.1
297
+ version: '0'
298
298
  requirements: []
299
299
  rubyforge_project:
300
- rubygems_version: 2.6.11
300
+ rubygems_version: 2.6.13
301
301
  signing_key:
302
302
  specification_version: 4
303
303
  summary: ActionSubscriber is a DSL that allows a rails app to consume messages from