action_subscriber 5.2.0 → 5.2.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
  SHA256:
3
- metadata.gz: eb97087f5a6958b61a4d441245e224c601dc9cb1424251f86aacca5700e327a8
4
- data.tar.gz: de4d85f2ba2e8aab277d07a51966ef60b6a639d0ff0dc65e2bac2adda2cfd389
3
+ metadata.gz: eb1ca4ca911a916fbf94ef776989b5275eb89ed0dcb7923fc77c03b992018867
4
+ data.tar.gz: d3a587bc5c18c0a99179737433d97f09e838494c9dc94ee738edf34f224e326b
5
5
  SHA512:
6
- metadata.gz: 3c1890c8861acdc67a4f6e1d3865980ef497820dd2b02038321bebab9248fee398176097c7f8d4d92332144719ae610d867ddbef93862ecc0e66781992b42036
7
- data.tar.gz: d8149dbee4e94533b2bc758addf25f66ef8b0c872d3d919dc685486e482ab5127f54fedccd130dd1532809e4bc847c6e381dc786266edbcf102fea5bb84ed22d
6
+ metadata.gz: 06dedc9fc3894fee2eb08091907537118c27b3a7f89ee67caa3a013a920fbc4ffefe867f018d61a3a2b2711799da9de85b762318f0a4db261d2643d59c8d3f31
7
+ data.tar.gz: f1f57d44e9db31f7aed1440651b7741fe3b203a48aa11e884325236ecb88733009fced7c1281bbfb48439eb4108042dbcaed2044d1c5c7c82d047ca8d1189dc7
@@ -30,9 +30,22 @@ module ActionSubscriber
30
30
  ::MarchHare::ThreadPools.fixed_of_size(options[:threadpool_size])
31
31
  end
32
32
  connection = ::MarchHare.connect(options)
33
+ connection.on_blocked do |reason|
34
+ on_blocked(reason)
35
+ end
36
+ connection.on_unblocked do
37
+ on_unblocked
38
+ end
39
+ connection
33
40
  else
34
41
  connection = ::Bunny.new(options)
35
42
  connection.start
43
+ connection.on_blocked do |blocked_message|
44
+ on_blocked(blocked_message.reason)
45
+ end
46
+ connection.on_unblocked do
47
+ on_unblocked
48
+ end
36
49
  connection
37
50
  end
38
51
  end
@@ -59,5 +72,15 @@ module ActionSubscriber
59
72
  }
60
73
  end
61
74
  private_class_method :connection_options
75
+
76
+ def self.on_blocked(reason)
77
+ ::ActiveSupport::Notifications.instrument("connection_blocked.action_subscriber", :reason => reason)
78
+ end
79
+ private_class_method :on_blocked
80
+
81
+ def self.on_unblocked
82
+ ::ActiveSupport::Notifications.instrument("connection_unblocked.action_subscriber")
83
+ end
84
+ private_class_method :on_unblocked
62
85
  end
63
86
  end
@@ -1,3 +1,3 @@
1
1
  module ActionSubscriber
2
- VERSION = "5.2.0"
2
+ VERSION = "5.2.1"
3
3
  end
@@ -0,0 +1,63 @@
1
+ require "spec_helper"
2
+
3
+ describe ::ActionSubscriber::RabbitConnection do
4
+ let(:reason) { "low on disk" }
5
+
6
+ before { ActionSubscriber.draw_routes {} }
7
+
8
+ context "on_block" do
9
+ if ::RUBY_PLATFORM == "java"
10
+ def trigger_mocked_blocking_event(connection, reason)
11
+ amqp_message = ::Java::ComRabbitmqClient::AMQP::Connection::Blocked::Builder.new.
12
+ reason(reason).build
13
+ amq_command = ::Java::ComRabbitmqClientImpl::AMQCommand.new(amqp_message)
14
+
15
+ connection.send(:processControlCommand, amq_command)
16
+ end
17
+ else
18
+ def trigger_mocked_blocking_event(connection, reason)
19
+ connection.send(:handle_frame, 0, ::AMQ::Protocol::Connection::Blocked.new(reason))
20
+ end
21
+ end
22
+
23
+ it "can deliver an on_blocked message" do
24
+ expect(::ActiveSupport::Notifications).to receive(:instrument).
25
+ with("connection_blocked.action_subscriber", :reason => reason)
26
+
27
+ described_class.with_connection do |connection|
28
+ # NOTE: Trigger the receiving of a blocked message from the broker.
29
+ # It's a bit of a hack but it is a more realistic test without changing
30
+ # memory alarms.
31
+ trigger_mocked_blocking_event(connection, reason)
32
+ end
33
+ end
34
+ end
35
+
36
+ context "on_unblocked" do
37
+ if ::RUBY_PLATFORM == "java"
38
+ def trigger_mocked_unblocked_event(connection, reason)
39
+ amqp_message = ::Java::ComRabbitmqClient::AMQP::Connection::Unblocked::Builder.new.
40
+ build
41
+ amq_command = ::Java::ComRabbitmqClientImpl::AMQCommand.new(amqp_message)
42
+
43
+ connection.send(:processControlCommand, amq_command)
44
+ end
45
+ else
46
+ def trigger_mocked_unblocked_event(connection, reason)
47
+ connection.send(:handle_frame, 0, ::AMQ::Protocol::Connection::Unblocked.new)
48
+ end
49
+ end
50
+
51
+ it "can deliver an on_unblocked message" do
52
+ expect(::ActiveSupport::Notifications).to receive(:instrument).
53
+ with("connection_unblocked.action_subscriber")
54
+
55
+ described_class.with_connection do |connection|
56
+ # NOTE: Trigger the receiving of an unblocked message from the broker.
57
+ # It's a bit of a hack but it is a more realistic test without changing
58
+ # memory alarms.
59
+ trigger_mocked_unblocked_event(connection, reason)
60
+ end
61
+ end
62
+ end
63
+ 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.2.0
4
+ version: 5.2.1
5
5
  platform: ruby
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: 2020-05-15 00:00:00.000000000 Z
15
+ date: 2020-05-19 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activesupport
@@ -273,6 +273,7 @@ files:
273
273
  - spec/lib/action_subscriber/middleware/error_handler_spec.rb
274
274
  - spec/lib/action_subscriber/middleware/router_spec.rb
275
275
  - spec/lib/action_subscriber/middleware/runner_spec.rb
276
+ - spec/lib/action_subscriber/rabbit_connection_spec.rb
276
277
  - spec/lib/action_subscriber/router_spec.rb
277
278
  - spec/lib/action_subscriber/subscribable_spec.rb
278
279
  - spec/spec_helper.rb
@@ -324,6 +325,7 @@ test_files:
324
325
  - spec/lib/action_subscriber/middleware/error_handler_spec.rb
325
326
  - spec/lib/action_subscriber/middleware/router_spec.rb
326
327
  - spec/lib/action_subscriber/middleware/runner_spec.rb
328
+ - spec/lib/action_subscriber/rabbit_connection_spec.rb
327
329
  - spec/lib/action_subscriber/router_spec.rb
328
330
  - spec/lib/action_subscriber/subscribable_spec.rb
329
331
  - spec/spec_helper.rb