action_subscriber 2.0.0 → 2.0.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: 8f4e53b712b617695c3fd68102e7990d72af09ff
4
- data.tar.gz: 7cf9d5f4916f076cfdc864ec9598b147c22d91f9
3
+ metadata.gz: fa7ffc8e113cf3414e95bd9ff2f4271716316da3
4
+ data.tar.gz: bb9f4b158454c734e75484f8d3fb722ea9817b3d
5
5
  SHA512:
6
- metadata.gz: d087f075d3a1f55742535dc39fd835f342593356858899720403518f39e601095f61aabbbcb3c560c479a60d2d9a20b9979452a0bf63c4cd543cdac672cc6ffb
7
- data.tar.gz: 83310fb4e0d30815ed28dbacc75adab0e4660e446149e0009d806b1df63d0c2088c248f47c523a6727c6e34414b60b08d70ead61711324637f0db4a328e30e8d
6
+ metadata.gz: e3495e8deb06c7ec7540a3cfb0f8080badcbfaa6565e9f1839bdf515c6c557997727e60802f95bca40683db7b5b98d2338eff316575f609c3d2b8616e3503bee
7
+ data.tar.gz: 2a34bf987ad18fa9b5d8fd852c8148173dbcc5b0bbf94329cd89ccbead8d66c152df1d3a766b9badfbf5baf5ce988a3c99e5c857cb82dc5f152fe8b2e075e661
@@ -96,8 +96,7 @@ module ActionSubscriber
96
96
  wait_loops = 0
97
97
  ::ActionSubscriber::Babou.stop_receving_messages!
98
98
 
99
- # Going to wait until the thread pool drains or we wait for 1000 seconds
100
- while ::ActionSubscriber::Threadpool.pool.busy_size > 0 && wait_loops < 1000
99
+ while ::ActionSubscriber::Threadpool.pool.busy_size > 0 && wait_loops < ::ActionSubscriber.configuration.seconds_to_wait_for_graceful_shutdown
101
100
  puts "waiting for threadpool to empty (#{::ActionSubscriber::Threadpool.pool.busy_size})"
102
101
  Thread.pass
103
102
  wait_loops = wait_loops + 1
@@ -21,6 +21,7 @@ module ActionSubscriber
21
21
  next unless encoded_payload # empty queue
22
22
  ::ActiveSupport::Notifications.instrument "popped_event.action_subscriber", :payload_size => encoded_payload.bytesize, :queue => queue.name
23
23
  properties = {
24
+ :action => route.action,
24
25
  :channel => queue.channel,
25
26
  :content_type => properties[:content_type],
26
27
  :delivery_tag => delivery_info.delivery_tag,
@@ -44,6 +45,7 @@ module ActionSubscriber
44
45
  consumer.on_delivery do |delivery_info, properties, encoded_payload|
45
46
  ::ActiveSupport::Notifications.instrument "received_event.action_subscriber", :payload_size => encoded_payload.bytesize, :queue => queue.name
46
47
  properties = {
48
+ :action => route.action,
47
49
  :channel => queue.channel,
48
50
  :content_type => properties.content_type,
49
51
  :delivery_tag => delivery_info.delivery_tag,
@@ -12,6 +12,7 @@ module ActionSubscriber
12
12
  :port,
13
13
  :prefetch,
14
14
  :publisher_confirms,
15
+ :seconds_to_wait_for_graceful_shutdown,
15
16
  :threadpool_size,
16
17
  :timeout,
17
18
  :times_to_pop
@@ -25,8 +26,9 @@ module ActionSubscriber
25
26
  :mode => 'subscribe',
26
27
  :pop_interval => 100, # in milliseconds
27
28
  :port => 5672,
28
- :prefetch => 200,
29
+ :prefetch => 5,
29
30
  :publisher_confirms => false,
31
+ :seconds_to_wait_for_graceful_shutdown => 30,
30
32
  :threadpool_size => 8,
31
33
  :timeout => 1,
32
34
  :times_to_pop => 8
@@ -17,6 +17,7 @@ module ActionSubscriber
17
17
  next unless encoded_payload
18
18
  ::ActiveSupport::Notifications.instrument "popped_event.action_subscriber", :payload_size => encoded_payload.bytesize, :queue => queue.name
19
19
  properties = {
20
+ :action => route.action,
20
21
  :channel => queue.channel,
21
22
  :content_type => metadata.content_type,
22
23
  :delivery_tag => metadata.delivery_tag,
@@ -41,6 +42,7 @@ module ActionSubscriber
41
42
  consumer = queue.subscribe(route.queue_subscription_options) do |metadata, encoded_payload|
42
43
  ::ActiveSupport::Notifications.instrument "received_event.action_subscriber", :payload_size => encoded_payload.bytesize, :queue => queue.name
43
44
  properties = {
45
+ :action => route.action,
44
46
  :channel => queue.channel,
45
47
  :content_type => metadata.content_type,
46
48
  :delivery_tag => metadata.delivery_tag,
@@ -5,7 +5,8 @@ module ActionSubscriber
5
5
  class Env
6
6
  attr_accessor :payload
7
7
 
8
- attr_reader :content_type,
8
+ attr_reader :action,
9
+ :content_type,
9
10
  :encoded_payload,
10
11
  :exchange,
11
12
  :headers,
@@ -26,6 +27,7 @@ module ActionSubscriber
26
27
  # :message_id => String
27
28
  # :routing_key => String
28
29
  def initialize(subscriber, encoded_payload, properties)
30
+ @action = properties.fetch(:action)
29
31
  @channel = properties.fetch(:channel)
30
32
  @content_type = properties.fetch(:content_type)
31
33
  @delivery_tag = properties.fetch(:delivery_tag)
@@ -43,13 +45,6 @@ module ActionSubscriber
43
45
  @channel.ack(@delivery_tag, acknowledge_multiple_messages)
44
46
  end
45
47
 
46
- # Return the last element of the routing key to indicate which action
47
- # to route the payload to
48
- #
49
- def action
50
- routing_key.split('.').last.to_s
51
- end
52
-
53
48
  def reject
54
49
  requeue_message = true
55
50
  @channel.reject(@delivery_tag, requeue_message)
@@ -13,6 +13,7 @@ module ActionSubscriber
13
13
  end
14
14
 
15
15
  PROPERTIES_DEFAULTS = {
16
+ :action => :created,
16
17
  :channel => FakeChannel.new,
17
18
  :content_type => "text/plain",
18
19
  :delivery_tag => "XYZ",
@@ -71,6 +72,7 @@ end
71
72
  let(:app) { Proc.new { |inner_env| inner_env } }
72
73
  let(:env) { ActionSubscriber::Middleware::Env.new(UserSubscriber, 'encoded payload', message_properties) }
73
74
  let(:message_properties) {{
75
+ :action => :created,
74
76
  :channel => ::ActionSubscriber::RSpec::FakeChannel.new,
75
77
  :content_type => "text/plain",
76
78
  :delivery_tag => "XYZ",
@@ -1,3 +1,3 @@
1
1
  module ActionSubscriber
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.1"
3
3
  end
@@ -0,0 +1,24 @@
1
+ class CustomActionSubscriber < ActionSubscriber::Base
2
+ def wat
3
+ $messages << payload
4
+ end
5
+ end
6
+
7
+ describe "A subscriber with a custom action", :integration => true do
8
+ let(:draw_routes) do
9
+ ::ActionSubscriber.draw_routes do
10
+ route ::CustomActionSubscriber, :wat,
11
+ :queue => "unrelated_to_the_action",
12
+ :routing_key => "*.javascript_framework"
13
+ end
14
+ end
15
+
16
+ it "routes the message to the selected action" do
17
+ ::ActionSubscriber.auto_subscribe!
18
+ ::ActionSubscriber::Publisher.publish("react.javascript_framework", "Another?!?!", "events")
19
+
20
+ verify_expectation_within(2.0) do
21
+ expect($messages).to eq(Set.new(["Another?!?!"]))
22
+ end
23
+ end
24
+ end
@@ -7,7 +7,8 @@ describe ::ActionSubscriber::Configuration do
7
7
  specify { expect(subject.mode).to eq('subscribe') }
8
8
  specify { expect(subject.pop_interval).to eq(100) }
9
9
  specify { expect(subject.port).to eq(5672) }
10
- specify { expect(subject.prefetch).to eq(200) }
10
+ specify { expect(subject.prefetch).to eq(5) }
11
+ specify { expect(subject.seconds_to_wait_for_graceful_shutdown).to eq(30) }
11
12
  specify { expect(subject.threadpool_size).to eq(8) }
12
13
  specify { expect(subject.timeout).to eq(1) }
13
14
  specify { expect(subject.times_to_pop).to eq(8) }
@@ -2,6 +2,7 @@ describe ActionSubscriber::Middleware::Env do
2
2
  let(:channel) { double("channel") }
3
3
  let(:encoded_payload) { 'encoded_payload' }
4
4
  let(:properties){ {
5
+ :action => :created,
5
6
  :channel => channel,
6
7
  :content_type => "application/json",
7
8
  :delivery_tag => "XYZ",
@@ -16,7 +17,7 @@ describe ActionSubscriber::Middleware::Env do
16
17
 
17
18
  subject { described_class.new(subscriber, encoded_payload, properties) }
18
19
 
19
- specify { expect(subject.action).to eq("created") }
20
+ specify { expect(subject.action).to eq(:created) }
20
21
  specify { expect(subject.content_type).to eq(properties[:content_type]) }
21
22
  specify { expect(subject.exchange).to eq(properties[:exchange]) }
22
23
  specify { expect(subject.headers).to eq(properties[:headers]) }
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: 2.0.0
4
+ version: 2.0.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: 2016-01-11 00:00:00.000000000 Z
15
+ date: 2016-01-26 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activesupport
@@ -229,6 +229,7 @@ files:
229
229
  - spec/integration/at_most_once_spec.rb
230
230
  - spec/integration/automatic_reconnect_spec.rb
231
231
  - spec/integration/basic_subscriber_spec.rb
232
+ - spec/integration/custom_actions_spec.rb
232
233
  - spec/integration/custom_headers_spec.rb
233
234
  - spec/integration/decoding_payloads_spec.rb
234
235
  - spec/integration/inferred_routes_spec.rb
@@ -281,6 +282,7 @@ test_files:
281
282
  - spec/integration/at_most_once_spec.rb
282
283
  - spec/integration/automatic_reconnect_spec.rb
283
284
  - spec/integration/basic_subscriber_spec.rb
285
+ - spec/integration/custom_actions_spec.rb
284
286
  - spec/integration/custom_headers_spec.rb
285
287
  - spec/integration/decoding_payloads_spec.rb
286
288
  - spec/integration/inferred_routes_spec.rb