action_subscriber 2.4.0-java → 2.5.0.pre2-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -7
- data/lib/action_subscriber.rb +1 -0
- data/lib/action_subscriber/base.rb +59 -3
- data/lib/action_subscriber/bunny/subscriber.rb +4 -0
- data/lib/action_subscriber/march_hare/subscriber.rb +6 -0
- data/lib/action_subscriber/middleware/env.rb +2 -0
- data/lib/action_subscriber/route_set.rb +7 -1
- data/lib/action_subscriber/synchronizer.rb +15 -0
- data/lib/action_subscriber/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c6194a3af9eae1c2d4cf5334ac776096f8f2941
|
4
|
+
data.tar.gz: 688438729925400473d45c00ca9d721381ed659b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbfad9bf2929bc5e91fa5c17db51d8704bf26dcd63c6cbf90010043317d240cc48b1efa8ccf48f59c9c30b4aec0846dc8de9b5cc4cb33a3f4243ad7e2d37be91
|
7
|
+
data.tar.gz: c3d530b87d242352a5066f7ae91661ff0ea313556feccc4f40b5040367f703c33c4ac037160d9d47d4d09c995dc5e038307774451ffc72a4307f27e95454ebb0
|
data/.travis.yml
CHANGED
@@ -1,13 +1,10 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
-
|
4
|
-
- 2.0
|
5
|
-
- 2.1
|
6
|
-
- 2.2
|
7
|
-
- jruby-1.7
|
3
|
+
- 2.2.4
|
4
|
+
- 2.3.0
|
8
5
|
- jruby-9.0.4.0
|
6
|
+
- jruby-9.1.5.0
|
9
7
|
- jruby-head
|
10
|
-
- rbx-2
|
11
8
|
services:
|
12
9
|
- rabbitmq
|
13
10
|
sudo: false
|
@@ -15,4 +12,3 @@ cache: bundler
|
|
15
12
|
matrix:
|
16
13
|
allow_failures:
|
17
14
|
- rvm: jruby-head
|
18
|
-
- rvm: rbx-2
|
data/lib/action_subscriber.rb
CHANGED
@@ -27,6 +27,7 @@ require "action_subscriber/march_hare/subscriber"
|
|
27
27
|
require "action_subscriber/babou"
|
28
28
|
require "action_subscriber/publisher"
|
29
29
|
require "action_subscriber/publisher/async"
|
30
|
+
require "action_subscriber/synchronizer"
|
30
31
|
require "action_subscriber/route"
|
31
32
|
require "action_subscriber/route_set"
|
32
33
|
require "action_subscriber/router"
|
@@ -61,17 +61,73 @@ module ActionSubscriber
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def _at_least_once_filter
|
64
|
+
processed_acknowledgement = false
|
64
65
|
yield
|
65
|
-
acknowledge
|
66
|
+
processed_acknowledgement = acknowledge
|
66
67
|
rescue => error
|
67
68
|
::ActionSubscriber::MessageRetry.redeliver_message_with_backoff(env)
|
68
|
-
acknowledge
|
69
|
+
processed_acknowledgement = acknowledge
|
69
70
|
raise error
|
71
|
+
ensure
|
72
|
+
rejected_message = false
|
73
|
+
rejected_message = reject unless processed_acknowledgement
|
74
|
+
|
75
|
+
if !processed_acknowledgement && !rejected_message
|
76
|
+
Process.kill(:TTIN, Process.pid)
|
77
|
+
Process.kill(:USR2, Process.pid)
|
78
|
+
|
79
|
+
$stdout << <<-UNREJECTABLE
|
80
|
+
CANNOT ACKNOWLEDGE OR REJECT THE MESSAGE
|
81
|
+
|
82
|
+
This is a exceptional state for ActionSubscriber to enter and puts the current
|
83
|
+
Process in the position of "I can't get new work from RabbitMQ, but also
|
84
|
+
can't acknowledge or reject the work that I currently have" ... While rare
|
85
|
+
this state can happen.
|
86
|
+
|
87
|
+
Instead of continuing to try to process the message ActionSubscriber is
|
88
|
+
sending a Kill signal to the current running process to gracefully shutdown
|
89
|
+
so that the RabbitMQ server will purge any outstanding acknowledgements. If
|
90
|
+
you are running a process monitoring tool (like Upstart) the Subscriber
|
91
|
+
process will be restarted and be able to take on new work.
|
92
|
+
|
93
|
+
** Running a process monitoring tool like Upstart is recommended for this reason **
|
94
|
+
UNREJECTABLE
|
95
|
+
|
96
|
+
Process.kill(:TERM, Process.pid)
|
97
|
+
end
|
70
98
|
end
|
71
99
|
|
72
100
|
def _at_most_once_filter
|
73
|
-
|
101
|
+
processed_acknowledgement = false
|
102
|
+
processed_acknowledgement = acknowledge
|
74
103
|
yield
|
104
|
+
ensure
|
105
|
+
rejected_message = false
|
106
|
+
rejected_message = reject unless processed_acknowledgement
|
107
|
+
|
108
|
+
if !processed_acknowledgement && !rejected_message
|
109
|
+
Process.kill(:TTIN, Process.pid)
|
110
|
+
Process.kill(:USR2, Process.pid)
|
111
|
+
|
112
|
+
$stdout << <<-UNREJECTABLE
|
113
|
+
CANNOT ACKNOWLEDGE OR REJECT THE MESSAGE
|
114
|
+
|
115
|
+
This is a exceptional state for ActionSubscriber to enter and puts the current
|
116
|
+
Process in the position of "I can't get new work from RabbitMQ, but also
|
117
|
+
can't acknowledge or reject the work that I currently have" ... While rare
|
118
|
+
this state can happen.
|
119
|
+
|
120
|
+
Instead of continuing to try to process the message ActionSubscriber is
|
121
|
+
sending a Kill signal to the current running process to gracefully shutdown
|
122
|
+
so that the RabbitMQ server will purge any outstanding acknowledgements. If
|
123
|
+
you are running a process monitoring tool (like Upstart) the Subscriber
|
124
|
+
process will be restarted and be able to take on new work.
|
125
|
+
|
126
|
+
** Running a process monitoring tool like Upstart is recommended for this reason **
|
127
|
+
UNREJECTABLE
|
128
|
+
|
129
|
+
Process.kill(:TERM, Process.pid)
|
130
|
+
end
|
75
131
|
end
|
76
132
|
|
77
133
|
def reject
|
@@ -11,6 +11,10 @@ module ActionSubscriber
|
|
11
11
|
bunny_consumers.each(&:cancel)
|
12
12
|
end
|
13
13
|
|
14
|
+
def create_queue(channel, queue_name, queue_options)
|
15
|
+
::Bunny::Queue.new(channel, queue_name, queue_options)
|
16
|
+
end
|
17
|
+
|
14
18
|
def auto_pop!
|
15
19
|
# Because threadpools can be large we want to cap the number
|
16
20
|
# of times we will pop each time we poll the broker
|
@@ -7,6 +7,12 @@ module ActionSubscriber
|
|
7
7
|
march_hare_consumers.each(&:cancel)
|
8
8
|
end
|
9
9
|
|
10
|
+
def create_queue(channel, queue_name, queue_options)
|
11
|
+
queue = ::MarchHare::Queue.new(channel, queue_name, queue_options)
|
12
|
+
queue.declare!
|
13
|
+
queue
|
14
|
+
end
|
15
|
+
|
10
16
|
def auto_pop!
|
11
17
|
# Because threadpools can be large we want to cap the number
|
12
18
|
# of times we will pop each time we poll the broker
|
@@ -43,11 +43,13 @@ module ActionSubscriber
|
|
43
43
|
def acknowledge
|
44
44
|
acknowledge_multiple_messages = false
|
45
45
|
@channel.ack(@delivery_tag, acknowledge_multiple_messages)
|
46
|
+
true
|
46
47
|
end
|
47
48
|
|
48
49
|
def reject
|
49
50
|
requeue_message = true
|
50
51
|
@channel.reject(@delivery_tag, requeue_message)
|
52
|
+
true
|
51
53
|
end
|
52
54
|
|
53
55
|
def to_hash
|
@@ -26,8 +26,14 @@ module ActionSubscriber
|
|
26
26
|
|
27
27
|
def setup_queue(route)
|
28
28
|
channel = ::ActionSubscriber::RabbitConnection.subscriber_connection.create_channel
|
29
|
+
# Make channels threadsafe again! Believe Me!
|
30
|
+
# Accessing channels from multiple threads for messsage acknowledgement will crash
|
31
|
+
# a channel and stop messages from being received on that channel
|
32
|
+
# this isn't very clear in the documentation for march_hare/bunny, but it is
|
33
|
+
# explicitly addresses here: https://github.com/rabbitmq/rabbitmq-java-client/issues/53
|
34
|
+
channel = ::ActionSubscriber::Synchronizer.new(channel)
|
29
35
|
exchange = channel.topic(route.exchange)
|
30
|
-
queue = channel
|
36
|
+
queue = create_queue(channel, route.queue, :durable => route.durable)
|
31
37
|
queue.bind(exchange, :routing_key => route.routing_key)
|
32
38
|
queue
|
33
39
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "thread"
|
2
|
+
module ActionSubscriber
|
3
|
+
class Synchronizer
|
4
|
+
def initialize(delegate)
|
5
|
+
@delegate = delegate
|
6
|
+
@mutex = ::Mutex.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def method_missing(name, *args, &block)
|
10
|
+
@mutex.synchronize do
|
11
|
+
@delegate.public_send(name, *args, &block)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
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: 2.
|
4
|
+
version: 2.5.0.pre2
|
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-
|
15
|
+
date: 2016-09-12 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
requirement: !ruby/object:Gem::Requirement
|
@@ -223,6 +223,7 @@ files:
|
|
223
223
|
- lib/action_subscriber/router.rb
|
224
224
|
- lib/action_subscriber/rspec.rb
|
225
225
|
- lib/action_subscriber/subscribable.rb
|
226
|
+
- lib/action_subscriber/synchronizer.rb
|
226
227
|
- lib/action_subscriber/threadpool.rb
|
227
228
|
- lib/action_subscriber/uri.rb
|
228
229
|
- lib/action_subscriber/version.rb
|
@@ -271,12 +272,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
271
272
|
version: '0'
|
272
273
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
273
274
|
requirements:
|
274
|
-
- - "
|
275
|
+
- - ">"
|
275
276
|
- !ruby/object:Gem::Version
|
276
|
-
version:
|
277
|
+
version: 1.3.1
|
277
278
|
requirements: []
|
278
279
|
rubyforge_project:
|
279
|
-
rubygems_version: 2.
|
280
|
+
rubygems_version: 2.6.6
|
280
281
|
signing_key:
|
281
282
|
specification_version: 4
|
282
283
|
summary: ActionSubscriber is a DSL that allows a rails app to consume messages from a RabbitMQ broker.
|