action_subscriber 2.0.0.pre0-java → 2.0.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
2
  SHA1:
3
- metadata.gz: 704909d89faa6c4cb11c8b6627b68338a95f42f6
4
- data.tar.gz: e1b21845d9959e21cf6945ab3520d7c5ed44f7c4
3
+ metadata.gz: 939204017ecb3b17925a0ceca1442798b98ddcdc
4
+ data.tar.gz: 1780324c82d3dac0a2f0d36d00bfaa724296782f
5
5
  SHA512:
6
- metadata.gz: 9520afb5c807074447480240201f81e38784a30da8466266acb22dd434e7b69998674f1aea37f94691702d6c61f0e86c54477c8ca853da1f39328564aa56d11b
7
- data.tar.gz: 3380283dd6b6325d8bcdeda10f7f9314a2a5ba73dd6be8c3b25c2a63781dc4c13a110d41eb6a19aef03ac59974078b55ddf1f73de9e9f317d1692cd0f33b67f3
6
+ metadata.gz: 258b3dcf397203650f2fe7c5b6590ddc3cf5ce0c9e81d1352d3a50505fc58ffa9b0dbcb5ec16b929d3ae9bb41580e6c15ba993da71194873eb4104ab58f44ba1
7
+ data.tar.gz: 9235bf4d8f54c8616ff77f958da778d04cd4a3f6271968a74f35245ad9fbf9a52c9b7cf1cf642e04dfd71a5e3a7ea8d586d7986f06a3fd6f6e1fc94ac2ab8e86
@@ -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.pre0"
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.pre0
4
+ version: 2.0.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: 2016-01-05 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
  requirement: !ruby/object:Gem::Requirement
@@ -228,6 +228,7 @@ files:
228
228
  - spec/integration/at_most_once_spec.rb
229
229
  - spec/integration/automatic_reconnect_spec.rb
230
230
  - spec/integration/basic_subscriber_spec.rb
231
+ - spec/integration/custom_actions_spec.rb
231
232
  - spec/integration/custom_headers_spec.rb
232
233
  - spec/integration/decoding_payloads_spec.rb
233
234
  - spec/integration/inferred_routes_spec.rb
@@ -264,9 +265,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
264
265
  version: '0'
265
266
  required_rubygems_version: !ruby/object:Gem::Requirement
266
267
  requirements:
267
- - - ">"
268
+ - - ">="
268
269
  - !ruby/object:Gem::Version
269
- version: 1.3.1
270
+ version: '0'
270
271
  requirements: []
271
272
  rubyforge_project:
272
273
  rubygems_version: 2.5.0
@@ -279,6 +280,7 @@ test_files:
279
280
  - spec/integration/at_most_once_spec.rb
280
281
  - spec/integration/automatic_reconnect_spec.rb
281
282
  - spec/integration/basic_subscriber_spec.rb
283
+ - spec/integration/custom_actions_spec.rb
282
284
  - spec/integration/custom_headers_spec.rb
283
285
  - spec/integration/decoding_payloads_spec.rb
284
286
  - spec/integration/inferred_routes_spec.rb