action_subscriber 1.2.3-java → 1.3.0-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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf049755417490c97087d1592cf92c85d70c2885
|
4
|
+
data.tar.gz: 4f8cdc076da224e9db7b006aa52d3ac1a60affbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cdf9bf646a393521a30ca5333e908448203e92d33e6ed197106cfb94789cc0028f57569028749fb359034f6b326084e86680ad42037b774f71ed18523c95046
|
7
|
+
data.tar.gz: 2b6a2c16f9679a357edf75463c3105cad974d8acfad96e5b3129bf3c3a09bc470b503fcb5ee88f12a84a572fd33f403584b033f10a780b245ce7b359ca813236
|
data/bin/action_subscriber
CHANGED
@@ -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
|
-
|
43
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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.
|
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.
|
82
|
-
|
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
|
30
|
-
|
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)
|
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.
|
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-
|
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
|