action_subscriber 1.2.3-java → 1.3.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c37aef199e1ebe53ec1c92d918a4aa5c02802552
4
- data.tar.gz: 7a3b119a963a0d53b73494f2732cb986d3ab3ed2
3
+ metadata.gz: cf049755417490c97087d1592cf92c85d70c2885
4
+ data.tar.gz: 4f8cdc076da224e9db7b006aa52d3ac1a60affbc
5
5
  SHA512:
6
- metadata.gz: 7eb7a487fc9decbf89fdd5ef4e1f4cf74feb8b53d226dbbed1f6d85b2c77518ec460581e6b7522128dd70aba6d8ceaccb7a8bb54de1d52543477a97728f24365
7
- data.tar.gz: f1390c5905a605358687233b7951b9e64afd9b5c1c85bcbeb6ee2b82aa63763f24081980832ab9d52e42730a1347790816e5b1fc94efdad1060d7b688f101922
6
+ metadata.gz: 2cdf9bf646a393521a30ca5333e908448203e92d33e6ed197106cfb94789cc0028f57569028749fb359034f6b326084e86680ad42037b774f71ed18523c95046
7
+ data.tar.gz: 2b6a2c16f9679a357edf75463c3105cad974d8acfad96e5b3129bf3c3a09bc470b503fcb5ee88f12a84a572fd33f403584b033f10a780b245ce7b359ca813236
@@ -11,6 +11,7 @@ module ActionSubscriber
11
11
  class_option :mode
12
12
  class_option :host
13
13
  class_option :hosts
14
+ class_option :prefetch, :type => :numeric, :desc => "how many messages to hold in the local queue in subscribe mode"
14
15
  class_option :pop_interval, :type => :numeric, :desc => "how long to wait between asking for messages (in milliseconds)"
15
16
  class_option :port, :type => :numeric
16
17
  class_option :threadpool_size, :type => :numeric
@@ -35,27 +36,22 @@ module ActionSubscriber
35
36
  ::ActionSubscriber::Babou.auto_pop!
36
37
  when /subscribe/i then
37
38
  ::ActionSubscriber::Babou.start_subscribers
39
+ else
40
+ fail "ActionSubscriber.configuration.mode must be 'pop' or 'subscribe'. Currently set to '#{::ActionSubscriber.configuration.mode}'"
38
41
  end
39
42
  end
40
43
  end
41
44
 
42
- [:INT, :QUIT, :TERM].each do |signal|
43
- trap(signal) do
44
- puts "Stopping server..."
45
- wait_loops = 0
45
+ if ::RUBY_PLATFORM == "java"
46
+ at_exit do
46
47
  ::ActionSubscriber::Babou.stop_server!
47
-
48
- # Going to wait until the thread pool drains or we wait for 1000 seconds
49
- # Only waiting for shut down in pop mode
50
- if ::ActionSubscriber::Babou.pop?
51
- while ::ActionSubscriber::Threadpool.pool.busy_size > 0 && wait_loops < 1000
52
- Thread.pass
53
- wait_loops = wait_loops + 1
54
- sleep 1
55
- end
48
+ end
49
+ else
50
+ [:INT, :QUIT, :TERM].each do |signal|
51
+ trap(signal) do
52
+ ::ActionSubscriber::Babou.stop_server!
53
+ exit 0
56
54
  end
57
-
58
- exit 0
59
55
  end
60
56
  end
61
57
  end
@@ -18,7 +18,7 @@ module ActionSubscriber
18
18
  # default check interval to 100ms
19
19
  while true
20
20
  ::ActionSubscriber.auto_pop! unless shutting_down?
21
- sleep sleep_time
21
+ sleep sleep_time
22
22
  break if shutting_down?
23
23
  end
24
24
  end
@@ -74,12 +74,34 @@ module ActionSubscriber
74
74
  end
75
75
  end
76
76
 
77
- def self.stop_server!
77
+ def self.shutting_down?
78
+ !!@shutting_down
79
+ end
80
+
81
+ def self.stop_receving_messages!
78
82
  @shutting_down = true
83
+ ::Thread.new do
84
+ ::ActionSubscriber::Base.inherited_classes.each do |subscriber|
85
+ subscriber.cancel_consumers!
86
+ puts "finished cancelling consumers"
87
+ end
88
+ end.join
79
89
  end
80
90
 
81
- def self.shutting_down?
82
- !!@shutting_down
91
+ def self.stop_server!
92
+ puts "Stopping server..."
93
+ wait_loops = 0
94
+ ::ActionSubscriber::Babou.stop_receving_messages!
95
+
96
+ # Going to wait until the thread pool drains or we wait for 1000 seconds
97
+ while ::ActionSubscriber::Threadpool.pool.busy_size > 0 && wait_loops < 1000
98
+ puts "waiting for threadpool to empty (#{::ActionSubscriber::Threadpool.pool.busy_size})"
99
+ Thread.pass
100
+ wait_loops = wait_loops + 1
101
+ sleep 1
102
+ end
103
+
104
+ puts "threadpool empty. Shutting down"
83
105
  end
84
106
 
85
107
  def self.subscribers_loaded?
@@ -1,6 +1,15 @@
1
1
  module ActionSubscriber
2
2
  module Bunny
3
3
  module Subscriber
4
+ def bunny_consumers
5
+ @bunny_consumers ||= []
6
+ end
7
+
8
+ def cancel_consumers!
9
+ puts "cancelling consumers for #{self}"
10
+ bunny_consumers.each(&:cancel)
11
+ end
12
+
4
13
  def auto_pop!
5
14
  # Because threadpools can be large we want to cap the number
6
15
  # of times we will pop each time we poll the broker
@@ -26,8 +35,10 @@ module ActionSubscriber
26
35
 
27
36
  def auto_subscribe!
28
37
  queues.each do |queue|
29
- queue.channel.prefetch(::ActionSubscriber.config.prefetch) if acknowledge_messages?
30
- queue.subscribe(queue_subscription_options) do |delivery_info, properties, encoded_payload|
38
+ channel = queue.channel
39
+ channel.prefetch(::ActionSubscriber.config.prefetch) if acknowledge_messages?
40
+ consumer = ::Bunny::Consumer.new(channel, queue, channel.generate_consumer_tag, !acknowledge_messages?)
41
+ consumer.on_delivery do |delivery_info, properties, encoded_payload|
31
42
  ::ActiveSupport::Notifications.instrument "received_event.action_subscriber", :payload_size => encoded_payload.bytesize, :queue => queue.name
32
43
  properties = {
33
44
  :channel => queue.channel,
@@ -40,6 +51,8 @@ module ActionSubscriber
40
51
  env = ::ActionSubscriber::Middleware::Env.new(self, encoded_payload, properties)
41
52
  enqueue_env(env)
42
53
  end
54
+ bunny_consumers << consumer
55
+ queue.subscribe_with(consumer)
43
56
  end
44
57
  end
45
58
 
@@ -1,6 +1,11 @@
1
1
  module ActionSubscriber
2
2
  module MarchHare
3
3
  module Subscriber
4
+ def cancel_consumers!
5
+ puts "cancelling consumers for #{self}"
6
+ march_hare_consumers.each(&:cancel)
7
+ end
8
+
4
9
  def auto_pop!
5
10
  # Because threadpools can be large we want to cap the number
6
11
  # of times we will pop each time we poll the broker
@@ -30,7 +35,7 @@ module ActionSubscriber
30
35
  def auto_subscribe!
31
36
  queues.each do |queue|
32
37
  queue.channel.prefetch = ::ActionSubscriber.config.prefetch if acknowledge_messages?
33
- queue.subscribe(queue_subscription_options) do |header, encoded_payload|
38
+ consumer = queue.subscribe(queue_subscription_options) do |header, encoded_payload|
34
39
  ::ActiveSupport::Notifications.instrument "received_event.action_subscriber", :payload_size => encoded_payload.bytesize, :queue => queue.name
35
40
  properties = {
36
41
  :channel => queue.channel,
@@ -43,9 +48,15 @@ module ActionSubscriber
43
48
  env = ::ActionSubscriber::Middleware::Env.new(self, encoded_payload, properties)
44
49
  enqueue_env(env)
45
50
  end
51
+
52
+ march_hare_consumers << consumer
46
53
  end
47
54
  end
48
55
 
56
+ def march_hare_consumers
57
+ @march_hare_consumers ||= []
58
+ end
59
+
49
60
  private
50
61
 
51
62
  def enqueue_env(env)
@@ -1,3 +1,3 @@
1
1
  module ActionSubscriber
2
- VERSION = "1.2.3"
2
+ VERSION = "1.3.0"
3
3
  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: 1.2.3
4
+ version: 1.3.0
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: 2015-10-13 00:00:00.000000000 Z
15
+ date: 2015-10-21 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  requirement: !ruby/object:Gem::Requirement