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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: a8825a5aee9ef249779a75bbddaf90debf489a6afe2aea23af9638a5582e34cf
4
- data.tar.gz: f488f680b5711d9cc2fee713dffc971d719b743fa4329031f73a57ea3547e46a
2
+ SHA1:
3
+ metadata.gz: 5c9565dc4ed32426228f63f4a74e7478ce4dcb74
4
+ data.tar.gz: eb2893c3584ba9d237328939064299405b94819e
5
5
  SHA512:
6
- metadata.gz: dd3f1a35eddd3e826bd3887ef97fe9bd0380f32d994bd44db5e3c2bdf1f20af76391abbdadc785edd4135ee6258301707940028770b53fba1bd1e3086364c3f8
7
- data.tar.gz: 771048790b48ef9fcdb7caa17724e28a7ae72a79d97ed65920c85883094a4f368dad21f1dbf9d371d2e709f31c53f5ebf961df8c11eae973a9e642f282025820
6
+ metadata.gz: 2b2c463f546b4fa3a979c0d6c55c4982f8abd7c4c253bcf9263fa62c96662ef5f8abe36483bd239bc4e7bee8314977261804ef5db9b93ac04f6c00d013960f4f
7
+ data.tar.gz: 3de474dfb99966ace57d9d9797860b627c8d4f85055c46b2f709c4b546843260c82d451fa824e9bb80b7d56243d073bc9fd2d4b8795baca00e0377a1edb1ef57
data/.travis.yml CHANGED
@@ -4,6 +4,7 @@ rvm:
4
4
  - 2.3.3
5
5
  - jruby-9.0.5.0
6
6
  - jruby-9.1.7.0
7
+ - jruby-9.1.12.0
7
8
  - jruby-head
8
9
  services:
9
10
  - rabbitmq
@@ -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.fetch(:message_id, ::SecureRandom.hex(3))
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
- @channel.ack(@delivery_tag, acknowledge_multiple_messages)
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
- @channel.nack(@delivery_tag, nack_multiple_messages, requeue_message)
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
- @channel.reject(@delivery_tag, requeue_message)
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
@@ -1,3 +1,3 @@
1
1
  module ActionSubscriber
2
- VERSION = "5.1.3.pre2"
2
+ VERSION = "5.1.4"
3
3
  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.3.pre2
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: 2018-11-07 00:00:00.000000000 Z
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: 1.3.1
297
+ version: '0'
298
298
  requirements: []
299
299
  rubyforge_project:
300
- rubygems_version: 2.6.11
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