action_subscriber 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -1
- data/README.md +1 -0
- data/action_subscriber.gemspec +13 -12
- data/lib/action_subscriber/base.rb +1 -1
- data/lib/action_subscriber/default_routing.rb +1 -1
- data/lib/action_subscriber/rabbit_connection.rb +50 -25
- data/lib/action_subscriber/version.rb +1 -1
- data/spec/integration/around_filters_spec.rb +3 -2
- data/spec/integration/at_least_once_spec.rb +3 -2
- data/spec/integration/at_most_once_spec.rb +3 -2
- data/spec/integration/automatic_reconnect_spec.rb +12 -13
- data/spec/integration/basic_subscriber_spec.rb +7 -6
- data/spec/integration/decoding_payloads_spec.rb +12 -10
- data/spec/integration/manual_acknowledgement_spec.rb +3 -2
- data/spec/spec_helper.rb +16 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 102687ae41f4f249b2ab5b0ec31dacf113ba7524
|
4
|
+
data.tar.gz: ccd09cd67af23fb625d8a81bdfae9480ce31b5e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5b1384dac0a211fea7d582547a912d6206f18409256ac10e0ed0a544190bf56cc55467924c7db373fe5e0865126ff14695dcd7f4e02da7210f649db6ccdd637
|
7
|
+
data.tar.gz: 384052e8b79236ab615c4c2ab34bb605884800fb6bc062b2776cbe6883265389eebbeed7306c959896a7fdcfb8d8b9a993c209cc671dc4e50885123f222be3e2
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
[![Build Status](https://travis-ci.org/moneydesktop/action_subscriber.svg?branch=master)](https://travis-ci.org/moneydesktop/action_subscriber)
|
2
2
|
[![Code Climate](https://codeclimate.com/github/moneydesktop/action_subscriber/badges/gpa.svg)](https://codeclimate.com/github/moneydesktop/action_subscriber)
|
3
3
|
[![Dependency Status](https://gemnasium.com/moneydesktop/action_subscriber.svg)](https://gemnasium.com/moneydesktop/action_subscriber)
|
4
|
+
[![Join the chat at https://gitter.im/moneydesktop/action_subscriber](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/moneydesktop/action_subscriber?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
4
5
|
|
5
6
|
ActionSubscriber
|
6
7
|
=================
|
data/action_subscriber.gemspec
CHANGED
@@ -4,19 +4,20 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'action_subscriber/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name
|
8
|
-
spec.version
|
9
|
-
spec.authors
|
10
|
-
spec.email
|
11
|
-
spec.description
|
12
|
-
spec.summary
|
13
|
-
spec.homepage
|
14
|
-
spec.license
|
7
|
+
spec.name = "action_subscriber"
|
8
|
+
spec.version = ActionSubscriber::VERSION
|
9
|
+
spec.authors = ["Brian Stien","Adam Hutchison","Brandon Dewitt","Devin Christensen","Michael Ries"]
|
10
|
+
spec.email = ["brianastien@gmail.com","liveh2o@gmail.com","brandonsdewitt@gmail.com","quixoten@gmail.com","michael@riesd.com"]
|
11
|
+
spec.description = %q{ActionSubscriber is a DSL that allows a rails app to consume messages from a RabbitMQ broker.}
|
12
|
+
spec.summary = %q{ActionSubscriber is a DSL that allows a rails app to consume messages from a RabbitMQ broker.}
|
13
|
+
spec.homepage = "https://github.com/moneydesktop/action_subscriber"
|
14
|
+
spec.license = "MIT"
|
15
15
|
|
16
|
-
spec.files
|
17
|
-
spec.executables
|
18
|
-
spec.test_files
|
19
|
-
spec.require_paths
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.0")
|
20
21
|
|
21
22
|
spec.add_dependency 'activesupport', '>= 3.2'
|
22
23
|
|
@@ -8,7 +8,7 @@ module ActionSubscriber
|
|
8
8
|
queue_name = queue_name_for_method(method_name)
|
9
9
|
routing_key_name = routing_key_name_for_method(method_name)
|
10
10
|
|
11
|
-
channel =
|
11
|
+
channel = connection.create_channel
|
12
12
|
exchange = channel.topic(exchange_name)
|
13
13
|
queue = channel.queue(queue_name)
|
14
14
|
queue.bind(exchange, :routing_key => routing_key_name)
|
@@ -2,29 +2,63 @@ require 'thread'
|
|
2
2
|
|
3
3
|
module ActionSubscriber
|
4
4
|
module RabbitConnection
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
5
|
+
SUBSCRIBER_CONNECTION_MUTEX = ::Mutex.new
|
6
|
+
PUBLISHER_CONNECTION_MUTEX = ::Mutex.new
|
7
|
+
|
8
|
+
def self.publisher_connected?
|
9
|
+
publisher_connection.try(:connected?)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.publisher_connection
|
13
|
+
SUBSCRIBER_CONNECTION_MUTEX.synchronize do
|
14
|
+
return @publisher_connection if @publisher_connection
|
15
|
+
@publisher_connection = create_connection
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.publisher_disconnect!
|
20
|
+
SUBSCRIBER_CONNECTION_MUTEX.synchronize do
|
21
|
+
if @publisher_connection && @publisher_connection.connected?
|
22
|
+
@publisher_connection.close
|
15
23
|
end
|
16
|
-
|
24
|
+
|
25
|
+
@publisher_connection = nil
|
17
26
|
end
|
18
27
|
end
|
19
28
|
|
20
|
-
def self.
|
21
|
-
|
29
|
+
def self.subscriber_connected?
|
30
|
+
subscriber_connection.try(:connected?)
|
22
31
|
end
|
23
32
|
|
24
|
-
def self.
|
25
|
-
|
33
|
+
def self.subscriber_connection
|
34
|
+
SUBSCRIBER_CONNECTION_MUTEX.synchronize do
|
35
|
+
return @subscriber_connection if @subscriber_connection
|
36
|
+
@subscriber_connection = create_connection
|
37
|
+
end
|
26
38
|
end
|
27
39
|
|
40
|
+
def self.subscriber_disconnect!
|
41
|
+
SUBSCRIBER_CONNECTION_MUTEX.synchronize do
|
42
|
+
if @subscriber_connection && @subscriber_connection.connected?
|
43
|
+
@subscriber_connection.close
|
44
|
+
end
|
45
|
+
|
46
|
+
@subscriber_connection = nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Private API
|
51
|
+
def self.create_connection
|
52
|
+
if ::RUBY_PLATFORM == "java"
|
53
|
+
connection = ::MarchHare.connect(connection_options)
|
54
|
+
else
|
55
|
+
connection = ::Bunny.new(connection_options)
|
56
|
+
connection.start
|
57
|
+
connection
|
58
|
+
end
|
59
|
+
end
|
60
|
+
private_class_method :create_connection
|
61
|
+
|
28
62
|
def self.connection_options
|
29
63
|
{
|
30
64
|
:heartbeat => ::ActionSubscriber.configuration.heartbeat,
|
@@ -36,15 +70,6 @@ module ActionSubscriber
|
|
36
70
|
:recover_from_connection_close => true,
|
37
71
|
}
|
38
72
|
end
|
39
|
-
|
40
|
-
def self.disconnect!
|
41
|
-
CONNECTION_MUTEX.synchronize do
|
42
|
-
if @connection && @connection.connected?
|
43
|
-
@connection.close
|
44
|
-
end
|
45
|
-
|
46
|
-
@connection = nil
|
47
|
-
end
|
48
|
-
end
|
73
|
+
private_class_method :connection_options
|
49
74
|
end
|
50
75
|
end
|
@@ -31,8 +31,9 @@ describe "subscriber filters", :integration => true do
|
|
31
31
|
channel = connection.create_channel
|
32
32
|
exchange = channel.topic("events")
|
33
33
|
exchange.publish("hEY Guyz!", :routing_key => "insta.first")
|
34
|
-
sleep 0.1
|
35
34
|
|
36
|
-
|
35
|
+
verify_expectation_within(1.0) do
|
36
|
+
expect($messages).to eq [:whisper_before, :yell_before, "hEY Guyz!", :yell_after, :whisper_after]
|
37
|
+
end
|
37
38
|
end
|
38
39
|
end
|
@@ -16,8 +16,9 @@ describe "at_least_once! mode", :integration => true do
|
|
16
16
|
channel = connection.create_channel
|
17
17
|
exchange = channel.topic("events")
|
18
18
|
exchange.publish("GrumpFace", :routing_key => "gorby_puff.grumpy")
|
19
|
-
sleep 0.1
|
20
19
|
|
21
|
-
|
20
|
+
verify_expectation_within(1.0) do
|
21
|
+
expect($messages).to eq Set.new(["GrumpFace::0","GrumpFace::1","GrumpFace::2"])
|
22
|
+
end
|
22
23
|
end
|
23
24
|
end
|
@@ -16,8 +16,9 @@ describe "at_most_once! mode", :integration => true do
|
|
16
16
|
channel = connection.create_channel
|
17
17
|
exchange = channel.topic("events")
|
18
18
|
exchange.publish("All Pokemon have been caught", :routing_key => "pokemon.caught_em_all")
|
19
|
-
sleep 0.1
|
20
19
|
|
21
|
-
|
20
|
+
verify_expectation_within(1.0) do
|
21
|
+
expect($messages.size).to eq 1
|
22
|
+
end
|
22
23
|
end
|
23
24
|
end
|
@@ -16,15 +16,22 @@ describe "Automatically reconnect on connection failure", :integration => true,
|
|
16
16
|
channel = connection.create_channel
|
17
17
|
exchange = channel.topic("events")
|
18
18
|
exchange.publish("First", :routing_key => "gus.spoke")
|
19
|
-
|
19
|
+
verify_expectation_within(5.0) do
|
20
|
+
expect($messages).to eq(Set.new(["First"]))
|
21
|
+
end
|
20
22
|
|
21
23
|
close_all_connections!
|
22
|
-
|
24
|
+
sleep 5.0
|
25
|
+
verify_expectation_within(5.0) do
|
26
|
+
expect(connection).to be_open
|
27
|
+
end
|
23
28
|
|
29
|
+
channel = connection.create_channel
|
30
|
+
exchange = channel.topic("events")
|
24
31
|
exchange.publish("Second", :routing_key => "gus.spoke")
|
25
|
-
|
26
|
-
|
27
|
-
|
32
|
+
verify_expectation_within(5.0) do
|
33
|
+
expect($messages).to eq(Set.new(["First", "Second"]))
|
34
|
+
end
|
28
35
|
end
|
29
36
|
|
30
37
|
def close_all_connections!
|
@@ -32,12 +39,4 @@ describe "Automatically reconnect on connection failure", :integration => true,
|
|
32
39
|
http_client.close_connection(conn_info.name)
|
33
40
|
end
|
34
41
|
end
|
35
|
-
|
36
|
-
def sleep_until_reconnected
|
37
|
-
100.times do
|
38
|
-
sleep 0.1
|
39
|
-
break if connection.open?
|
40
|
-
end
|
41
|
-
sleep 0.2
|
42
|
-
end
|
43
42
|
end
|
@@ -25,11 +25,11 @@ describe "A Basic Subscriber", :integration => true do
|
|
25
25
|
exchange = channel.topic("events")
|
26
26
|
exchange.publish("Ohai Booked", :routing_key => "greg.basic_push.booked")
|
27
27
|
exchange.publish("Ohai Cancelled", :routing_key => "basic.cancelled")
|
28
|
-
sleep 0.1
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
verify_expectation_within(2.0) do
|
30
|
+
::ActionSubscriber.auto_pop!
|
31
|
+
expect($messages).to eq(Set.new(["Ohai Booked", "Ohai Cancelled"]))
|
32
|
+
end
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -40,9 +40,10 @@ describe "A Basic Subscriber", :integration => true do
|
|
40
40
|
exchange = channel.topic("events")
|
41
41
|
exchange.publish("Ohai Booked", :routing_key => "greg.basic_push.booked")
|
42
42
|
exchange.publish("Ohai Cancelled", :routing_key => "basic.cancelled")
|
43
|
-
sleep 0.1
|
44
43
|
|
45
|
-
|
44
|
+
verify_expectation_within(2.0) do
|
45
|
+
expect($messages).to eq(Set.new(["Ohai Booked", "Ohai Cancelled"]))
|
46
|
+
end
|
46
47
|
end
|
47
48
|
end
|
48
49
|
end
|
@@ -18,12 +18,13 @@ describe "Payload Decoding", :integration => true do
|
|
18
18
|
channel = connection.create_channel
|
19
19
|
exchange = channel.topic("events")
|
20
20
|
exchange.publish(json_string, :routing_key => "twitter.tweet", :content_type => "application/json")
|
21
|
-
sleep 0.1
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
verify_expectation_within(2.0) do
|
23
|
+
expect($messages).to eq Set.new([{
|
24
|
+
:decoded => JSON.parse(json_string),
|
25
|
+
:raw => json_string,
|
26
|
+
}])
|
27
|
+
end
|
27
28
|
end
|
28
29
|
|
29
30
|
context "Custom Decoder" do
|
@@ -37,12 +38,13 @@ describe "Payload Decoding", :integration => true do
|
|
37
38
|
channel = connection.create_channel
|
38
39
|
exchange = channel.topic("events")
|
39
40
|
exchange.publish(json_string, :routing_key => "twitter.tweet", :content_type => content_type)
|
40
|
-
sleep 0.1
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
verify_expectation_within(2.0) do
|
43
|
+
expect($messages).to eq Set.new([{
|
44
|
+
:decoded => :foo,
|
45
|
+
:raw => json_string,
|
46
|
+
}])
|
47
|
+
end
|
46
48
|
end
|
47
49
|
end
|
48
50
|
end
|
@@ -20,8 +20,9 @@ describe "Manual Message Acknowledgment", :integration => true do
|
|
20
20
|
channel = connection.create_channel
|
21
21
|
exchange = channel.topic("events")
|
22
22
|
exchange.publish("BACON!", :routing_key => "bacon.served")
|
23
|
-
sleep 0.1
|
24
23
|
|
25
|
-
|
24
|
+
verify_expectation_within(2.0) do
|
25
|
+
expect($messages).to eq(Set.new(["BACON!::0", "BACON!::1", "BACON!::2"]))
|
26
|
+
end
|
26
27
|
end
|
27
28
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -20,13 +20,27 @@ RSpec.configure do |config|
|
|
20
20
|
|
21
21
|
config.before(:each, :integration => true) do
|
22
22
|
$messages = Set.new
|
23
|
-
::ActionSubscriber::RabbitConnection.
|
23
|
+
::ActionSubscriber::RabbitConnection.subscriber_connection
|
24
24
|
::ActionSubscriber.setup_queues!
|
25
25
|
end
|
26
26
|
config.after(:each, :integration => true) do
|
27
|
-
::ActionSubscriber::RabbitConnection.
|
27
|
+
::ActionSubscriber::RabbitConnection.subscriber_disconnect!
|
28
28
|
::ActionSubscriber::Base.inherited_classes.each do |klass|
|
29
29
|
klass.instance_variable_set("@_queues", nil)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
33
|
+
|
34
|
+
def verify_expectation_within(number_of_seconds, check_every = 0.02)
|
35
|
+
waiting_since = ::Time.now
|
36
|
+
begin
|
37
|
+
sleep check_every
|
38
|
+
yield
|
39
|
+
rescue RSpec::Expectations::ExpectationNotMetError => e
|
40
|
+
if ::Time.now - waiting_since > number_of_seconds
|
41
|
+
raise e
|
42
|
+
else
|
43
|
+
retry
|
44
|
+
end
|
45
|
+
end
|
46
|
+
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.0.
|
4
|
+
version: 1.0.5
|
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: 2015-
|
15
|
+
date: 2015-09-12 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: activesupport
|
@@ -233,7 +233,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
233
233
|
requirements:
|
234
234
|
- - ">="
|
235
235
|
- !ruby/object:Gem::Version
|
236
|
-
version: '0'
|
236
|
+
version: '2.0'
|
237
237
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
238
238
|
requirements:
|
239
239
|
- - ">="
|
@@ -241,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
241
241
|
version: '0'
|
242
242
|
requirements: []
|
243
243
|
rubyforge_project:
|
244
|
-
rubygems_version: 2.4.
|
244
|
+
rubygems_version: 2.4.8
|
245
245
|
signing_key:
|
246
246
|
specification_version: 4
|
247
247
|
summary: ActionSubscriber is a DSL that allows a rails app to consume messages from
|