action_subscriber 5.1.3.pre2-java → 5.1.4-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +1 -0
- data/lib/action_subscriber/middleware/env.rb +20 -4
- data/lib/action_subscriber/version.rb +1 -1
- data/spec/lib/action_subscriber/middleware/env_spec.rb +37 -0
- data/spec/spec_helper.rb +12 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5c9565dc4ed32426228f63f4a74e7478ce4dcb74
|
4
|
+
data.tar.gz: eb2893c3584ba9d237328939064299405b94819e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b2c463f546b4fa3a979c0d6c55c4982f8abd7c4c253bcf9263fa62c96662ef5f8abe36483bd239bc4e7bee8314977261804ef5db9b93ac04f6c00d013960f4f
|
7
|
+
data.tar.gz: 3de474dfb99966ace57d9d9797860b627c8d4f85055c46b2f709c4b546843260c82d451fa824e9bb80b7d56243d073bc9fd2d4b8795baca00e0377a1edb1ef57
|
data/.travis.yml
CHANGED
@@ -3,6 +3,10 @@ require "securerandom"
|
|
3
3
|
module ActionSubscriber
|
4
4
|
module Middleware
|
5
5
|
class Env
|
6
|
+
ACK_INSTRUMENT_KEY = "message_acked.action_subscriber".freeze
|
7
|
+
NACK_INSTRUMENT_KEY = "message_nacked.action_subscriber".freeze
|
8
|
+
REJECT_INSTRUMENT_KEY = "message_rejected.action_subscriber".freeze
|
9
|
+
|
6
10
|
attr_accessor :payload
|
7
11
|
|
8
12
|
attr_reader :action,
|
@@ -38,7 +42,7 @@ module ActionSubscriber
|
|
38
42
|
@has_been_nacked = false
|
39
43
|
@has_been_rejected = false
|
40
44
|
@headers = properties.fetch(:headers, {})
|
41
|
-
@message_id = properties
|
45
|
+
@message_id = properties[:message_id].presence || ::SecureRandom.hex(3)
|
42
46
|
@queue = properties.fetch(:queue)
|
43
47
|
@routing_key = properties.fetch(:routing_key)
|
44
48
|
@subscriber = subscriber
|
@@ -50,7 +54,9 @@ module ActionSubscriber
|
|
50
54
|
return true if @has_been_acked
|
51
55
|
acknowledge_multiple_messages = false
|
52
56
|
@has_been_acked = true
|
53
|
-
|
57
|
+
instrument_for(ACK_INSTRUMENT_KEY) do
|
58
|
+
@channel.ack(@delivery_tag, acknowledge_multiple_messages)
|
59
|
+
end
|
54
60
|
true
|
55
61
|
end
|
56
62
|
|
@@ -65,7 +71,9 @@ module ActionSubscriber
|
|
65
71
|
nack_multiple_messages = false
|
66
72
|
requeue_message = true
|
67
73
|
@has_been_nacked = true
|
68
|
-
|
74
|
+
instrument_for(NACK_INSTRUMENT_KEY) do
|
75
|
+
@channel.nack(@delivery_tag, nack_multiple_messages, requeue_message)
|
76
|
+
end
|
69
77
|
true
|
70
78
|
end
|
71
79
|
|
@@ -74,7 +82,9 @@ module ActionSubscriber
|
|
74
82
|
return true if @has_been_rejected
|
75
83
|
requeue_message = true
|
76
84
|
@has_been_rejected = true
|
77
|
-
|
85
|
+
instrument_for(REJECT_INSTRUMENT_KEY) do
|
86
|
+
@channel.reject(@delivery_tag, requeue_message)
|
87
|
+
end
|
78
88
|
true
|
79
89
|
end
|
80
90
|
|
@@ -107,6 +117,12 @@ module ActionSubscriber
|
|
107
117
|
@has_been_acked || @has_been_nacked || @has_been_rejected
|
108
118
|
end
|
109
119
|
|
120
|
+
def instrument_for(instrumentation_key)
|
121
|
+
::ActiveSupport::Notifications.instrument(instrumentation_key, :subscriber => subscriber.to_s, :routing_key => routing_key, :queue => queue) do
|
122
|
+
yield
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
110
126
|
def uses_acknowledgements?
|
111
127
|
@uses_acknowledgements
|
112
128
|
end
|
@@ -30,6 +30,33 @@ describe ActionSubscriber::Middleware::Env do
|
|
30
30
|
expect(channel).to receive(:ack).with(properties[:delivery_tag], false)
|
31
31
|
subject.acknowledge
|
32
32
|
end
|
33
|
+
|
34
|
+
it "instruments an acknowedgement" do
|
35
|
+
expect(channel).to receive(:ack).with(properties[:delivery_tag], false)
|
36
|
+
duration = nil
|
37
|
+
work = lambda { |_name, start, finish, _id, _payload| duration = finish - start }
|
38
|
+
with_instrumentation_subscription("message_acked.action_subscriber", work) do
|
39
|
+
subject.acknowledge
|
40
|
+
end
|
41
|
+
expect(duration).to_not be_nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#nack" do
|
46
|
+
it "sends a nack to rabbitmq" do
|
47
|
+
expect(channel).to receive(:nack).with(properties[:delivery_tag], false, true)
|
48
|
+
subject.nack
|
49
|
+
end
|
50
|
+
|
51
|
+
it "instruments a nack" do
|
52
|
+
expect(channel).to receive(:nack).with(properties[:delivery_tag], false, true)
|
53
|
+
duration = nil
|
54
|
+
work = lambda { |_name, start, finish, _id, _payload| duration = finish - start }
|
55
|
+
with_instrumentation_subscription("message_nacked.action_subscriber", work) do |c|
|
56
|
+
subject.nack
|
57
|
+
end
|
58
|
+
expect(duration).to_not be_nil
|
59
|
+
end
|
33
60
|
end
|
34
61
|
|
35
62
|
describe "#reject" do
|
@@ -37,6 +64,16 @@ describe ActionSubscriber::Middleware::Env do
|
|
37
64
|
expect(channel).to receive(:reject).with(properties[:delivery_tag], true)
|
38
65
|
subject.reject
|
39
66
|
end
|
67
|
+
|
68
|
+
it "instruments a rejection" do
|
69
|
+
expect(channel).to receive(:reject).with(properties[:delivery_tag], true)
|
70
|
+
duration = nil
|
71
|
+
work = lambda { |_name, start, finish, _id, _payload| duration = finish - start }
|
72
|
+
with_instrumentation_subscription("message_rejected.action_subscriber", work) do
|
73
|
+
subject.reject
|
74
|
+
end
|
75
|
+
expect(duration).to_not be_nil
|
76
|
+
end
|
40
77
|
end
|
41
78
|
|
42
79
|
describe "#to_hash" do
|
data/spec/spec_helper.rb
CHANGED
@@ -51,3 +51,15 @@ def verify_expectation_within(number_of_seconds, check_every = 0.02)
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
54
|
+
|
55
|
+
# This helper method allows us to verify a subscription is cleaned up after every test.
|
56
|
+
# Its arguments are the instrumentation key and a proc that contains the work to be
|
57
|
+
# performed for each notification.
|
58
|
+
def with_instrumentation_subscription(instrumentation_key, work)
|
59
|
+
subscription = ::ActiveSupport::Notifications.subscribe(instrumentation_key) do |name, start, finish, id, payload|
|
60
|
+
work.call(name, start, finish, id, payload)
|
61
|
+
end
|
62
|
+
yield
|
63
|
+
ensure
|
64
|
+
::ActiveSupport::Notifications.unsubscribe(subscription)
|
65
|
+
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.
|
4
|
+
version: 5.1.4
|
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:
|
15
|
+
date: 2019-06-07 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:
|
297
|
+
version: '0'
|
298
298
|
requirements: []
|
299
299
|
rubyforge_project:
|
300
|
-
rubygems_version: 2.6.
|
300
|
+
rubygems_version: 2.6.14.1
|
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
|