action_subscriber 1.0.4-java → 1.0.5-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: b4d9b95b805582ecb7730fabdfa3d99adac708f2
4
- data.tar.gz: 2a016a851347d77f3c2ebdbf83c6860455e0599b
3
+ metadata.gz: 1f4c2c6846b39cea78859c8fbaa677c35df08c84
4
+ data.tar.gz: 41c186e3e7465d4a7feb1252ae7ca983948bb630
5
5
  SHA512:
6
- metadata.gz: 98a8fbb5c315e381cf079a3e909991e1be22f2ef644e2204727356c85d509a01faf50496e58281d0b6f157e2eda89f3d148f549427372e62f9baf830dea1cba6
7
- data.tar.gz: 3aec2d0022224cb122acc2fd43d53513aa14bf491bc15076493aa4b77c80a72744e4cb345d87f5996fcae0fc0666a3abbfec7243af804520e2d483afa94537a2
6
+ metadata.gz: 4c3c4091f8bc4a243cfb5cb0639d9fcaf4c6aba62e99908e1a812a03f233aea2c09a5f66a962dfd59166326a128d40582b67a4519b297f2e00765734ce0ca32c
7
+ data.tar.gz: b7497d9da032a879f1506ac122d4ecc342e79020dd4886ee60464b35ee8c009e6f897aa9872c92523ef361bfb3e4fa600f20eb7151478f94b026e3160b671e9b
@@ -1,12 +1,17 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9
4
3
  - 2.0
5
4
  - 2.1
6
5
  - 2.2
7
6
  - jruby
7
+ - jruby-1.7
8
8
  - jruby-head
9
+ - rbx-2
9
10
  services:
10
11
  - rabbitmq
11
12
  sudo: false
12
13
  cache: bundler
14
+ matrix:
15
+ allow_failures:
16
+ - rvm: jruby-head
17
+ - rvm: rbx-2
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
  =================
@@ -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 = "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"
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 = `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"]
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
 
@@ -32,7 +32,7 @@ module ActionSubscriber
32
32
  #
33
33
 
34
34
  def self.connection
35
- ::ActionSubscriber::RabbitConnection.connection
35
+ ::ActionSubscriber::RabbitConnection.subscriber_connection
36
36
  end
37
37
 
38
38
  # Inherited callback, save a reference to our descendents
@@ -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 = ::ActionSubscriber::RabbitConnection.connection.create_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
- CONNECTION_MUTEX = ::Mutex.new
6
-
7
- def self.connect!
8
- CONNECTION_MUTEX.synchronize do
9
- return @connection if @connection
10
- if ::RUBY_PLATFORM == "java"
11
- @connection = ::MarchHare.connect(connection_options)
12
- else
13
- @connection = ::Bunny.new(connection_options)
14
- @connection.start
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
- @connection
24
+
25
+ @publisher_connection = nil
17
26
  end
18
27
  end
19
28
 
20
- def self.connected?
21
- connection && connection.connected?
29
+ def self.subscriber_connected?
30
+ subscriber_connection.try(:connected?)
22
31
  end
23
32
 
24
- def self.connection
25
- connect!
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
@@ -1,3 +1,3 @@
1
1
  module ActionSubscriber
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  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
- expect($messages).to eq [:whisper_before, :yell_before, "hEY Guyz!", :yell_after, :whisper_after]
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
- expect($messages).to eq Set.new(["GrumpFace::0","GrumpFace::1","GrumpFace::2"])
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
- expect($messages.size).to eq 1
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
- sleep 0.1
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
- sleep_until_reconnected
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
- sleep 0.1
26
-
27
- expect($messages).to eq(Set.new(["First", "Second"]))
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
- ::ActionSubscriber.auto_pop!
31
-
32
- expect($messages).to eq(Set.new(["Ohai Booked", "Ohai Cancelled"]))
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
- expect($messages).to eq(Set.new(["Ohai Booked", "Ohai Cancelled"]))
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
- expect($messages).to eq Set.new([{
24
- :decoded => JSON.parse(json_string),
25
- :raw => json_string,
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
- expect($messages).to eq Set.new([{
43
- :decoded => :foo,
44
- :raw => json_string,
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
- expect($messages).to eq(Set.new(["BACON!::0", "BACON!::1", "BACON!::2"]))
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
@@ -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.connect!
23
+ ::ActionSubscriber::RabbitConnection.subscriber_connection
24
24
  ::ActionSubscriber.setup_queues!
25
25
  end
26
26
  config.after(:each, :integration => true) do
27
- ::ActionSubscriber::RabbitConnection.disconnect!
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
4
+ version: 1.0.5
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-02-10 00:00:00.000000000 Z
15
+ date: 2015-09-12 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  requirement: !ruby/object:Gem::Requirement
@@ -232,7 +232,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
232
232
  requirements:
233
233
  - - '>='
234
234
  - !ruby/object:Gem::Version
235
- version: '0'
235
+ version: '2.0'
236
236
  required_rubygems_version: !ruby/object:Gem::Requirement
237
237
  requirements:
238
238
  - - '>='
@@ -240,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
240
240
  version: '0'
241
241
  requirements: []
242
242
  rubyforge_project:
243
- rubygems_version: 2.1.9
243
+ rubygems_version: 2.4.8
244
244
  signing_key:
245
245
  specification_version: 4
246
246
  summary: ActionSubscriber is a DSL that allows a rails app to consume messages from a RabbitMQ broker.