amqp-hermes 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +45 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +75 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/lib/amqp-hermes.rb +27 -0
- data/lib/amqp-hermes/connectivity.rb +48 -0
- data/lib/amqp-hermes/message.rb +12 -0
- data/lib/amqp-hermes/receiver.rb +68 -0
- data/lib/amqp-hermes/transmitter.rb +37 -0
- data/lib/amqp-hermes/version.rb +3 -0
- data/spec/amqp-hermes/connectivity_spec.rb +33 -0
- data/spec/amqp-hermes/receiver_spec.rb +78 -0
- data/spec/amqp-hermes/transmitter_spec.rb +58 -0
- data/spec/spec_helper.rb +13 -0
- metadata +140 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
gem "amqp", "~> 0.9"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.8.0"
|
10
|
+
gem "faker", "~> 1"
|
11
|
+
gem "rdoc", "~> 3.12"
|
12
|
+
gem "bundler", "~> 1.0.0"
|
13
|
+
gem "jeweler", "~> 1.8.3"
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
amq-client (0.9.2)
|
5
|
+
amq-protocol (>= 0.9.0)
|
6
|
+
eventmachine
|
7
|
+
amq-protocol (0.9.0)
|
8
|
+
amqp (0.9.4)
|
9
|
+
amq-client (~> 0.9.2)
|
10
|
+
amq-protocol (>= 0.9.0)
|
11
|
+
eventmachine
|
12
|
+
diff-lcs (1.1.3)
|
13
|
+
eventmachine (0.12.10)
|
14
|
+
faker (1.0.1)
|
15
|
+
i18n (~> 0.4)
|
16
|
+
git (1.2.5)
|
17
|
+
i18n (0.6.0)
|
18
|
+
jeweler (1.8.3)
|
19
|
+
bundler (~> 1.0)
|
20
|
+
git (>= 1.2.5)
|
21
|
+
rake
|
22
|
+
rdoc
|
23
|
+
json (1.6.5)
|
24
|
+
rake (0.9.2.2)
|
25
|
+
rdoc (3.12)
|
26
|
+
json (~> 1.4)
|
27
|
+
rspec (2.8.0)
|
28
|
+
rspec-core (~> 2.8.0)
|
29
|
+
rspec-expectations (~> 2.8.0)
|
30
|
+
rspec-mocks (~> 2.8.0)
|
31
|
+
rspec-core (2.8.0)
|
32
|
+
rspec-expectations (2.8.0)
|
33
|
+
diff-lcs (~> 1.1.2)
|
34
|
+
rspec-mocks (2.8.0)
|
35
|
+
|
36
|
+
PLATFORMS
|
37
|
+
ruby
|
38
|
+
|
39
|
+
DEPENDENCIES
|
40
|
+
amqp (~> 0.9)
|
41
|
+
bundler (~> 1.0.0)
|
42
|
+
faker (~> 1)
|
43
|
+
jeweler (~> 1.8.3)
|
44
|
+
rdoc (~> 3.12)
|
45
|
+
rspec (~> 2.8.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Wyngle, http://wyngle.com/
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
= amqp-hermes
|
2
|
+
|
3
|
+
A wrapper around ruby-amqp to make pub/sub live more easy.
|
4
|
+
|
5
|
+
== Synopsis
|
6
|
+
|
7
|
+
=== Sending a message
|
8
|
+
|
9
|
+
# plain and simple
|
10
|
+
tr = AMQP::Hermes::Transmitter.new("test.queue.testing")
|
11
|
+
tr.transmit "payload"
|
12
|
+
|
13
|
+
# or as json
|
14
|
+
tr.transmit { :foo => "bar", :quex => "stuff" }.to_json
|
15
|
+
|
16
|
+
# with AMQP options
|
17
|
+
tr.transmit "payload", :persistent => true
|
18
|
+
|
19
|
+
# on a different queue
|
20
|
+
tr.transmit "payload", :routing_key => "test.queue.real"
|
21
|
+
|
22
|
+
|
23
|
+
=== Receiving a message with the simple build in handler
|
24
|
+
|
25
|
+
re = AMQP::Hermes::Receiver.new("test.queue") # will listen on routing_key
|
26
|
+
# test.queue.* be default
|
27
|
+
while !re.messages.any?
|
28
|
+
sleep 0.1
|
29
|
+
end
|
30
|
+
|
31
|
+
puts re.messages.first.payload
|
32
|
+
|
33
|
+
=== Receiving with a custom handler
|
34
|
+
|
35
|
+
class MyCustomHandler
|
36
|
+
def receive(message)
|
37
|
+
if message.headers.routing_key =~ /test/
|
38
|
+
$stderr.puts "Just a test, nothing to worry about"
|
39
|
+
$stderr.puts message.payload
|
40
|
+
|
41
|
+
else
|
42
|
+
# ... do something incredible
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
re = AMQP::Hermes::Receiver.new("test.queue",
|
49
|
+
:handler => MyCustomHandler.new
|
50
|
+
)
|
51
|
+
|
52
|
+
while(true);
|
53
|
+
# the receiver is at the ball now
|
54
|
+
end
|
55
|
+
|
56
|
+
== Contributing to amqp-hermes
|
57
|
+
|
58
|
+
* Check out the latest master to make sure the feature hasn't been implemented
|
59
|
+
or the bug hasn't been fixed yet.
|
60
|
+
* Check out the issue tracker to make sure someone already hasn't requested it
|
61
|
+
and/or contributed it.
|
62
|
+
* Fork the project.
|
63
|
+
* Start a feature/bugfix branch.
|
64
|
+
* Commit and push until you are happy with your contribution.
|
65
|
+
* Make sure to add tests for it. This is important so I don't break it in a
|
66
|
+
future version unintentionally.
|
67
|
+
* Please try not to mess with the Rakefile, version, or history. If you want
|
68
|
+
to have your own version, or is otherwise necessary, that is fine, but
|
69
|
+
please isolate to its own commit so I can cherry-pick around it.
|
70
|
+
|
71
|
+
== Copyright
|
72
|
+
|
73
|
+
Copyright (c) 2012 Wyngle, http://wyngle.com/. See LICENSE.txt for
|
74
|
+
further details.
|
75
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "amqp-hermes"
|
18
|
+
gem.homepage = "http://github.com/wyngle/amqp-hermes"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Hermes; Messenger of the gods}
|
21
|
+
gem.description = %Q{Wrapper around ruby-amqp to make pub/sub easier}
|
22
|
+
gem.email = "hartog.de.mik@gmail.com"
|
23
|
+
gem.authors = ["Hartog C. de Mik"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "amqp-hermes #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/lib/amqp-hermes.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'amqp'
|
2
|
+
|
3
|
+
require "amqp-hermes/version"
|
4
|
+
require 'amqp-hermes/connectivity'
|
5
|
+
require 'amqp-hermes/transmitter'
|
6
|
+
require 'amqp-hermes/receiver'
|
7
|
+
require 'amqp-hermes/message'
|
8
|
+
|
9
|
+
module AMQP
|
10
|
+
module Hermes
|
11
|
+
def self.wait_for(something, test, max=50)
|
12
|
+
res = something.send(test)
|
13
|
+
unless [ true, false ].include?(res)
|
14
|
+
raise "Can only wait for true or false"
|
15
|
+
end
|
16
|
+
return 0 if res == true
|
17
|
+
|
18
|
+
wait_count = 0
|
19
|
+
while !something.send(test)
|
20
|
+
raise "Waited long enough" if ( wait_count += 1 ) > max
|
21
|
+
sleep 0.1
|
22
|
+
end
|
23
|
+
|
24
|
+
return wait_count
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module AMQP
|
2
|
+
module Hermes
|
3
|
+
module Connectivity
|
4
|
+
def connection
|
5
|
+
@connection || open_connection
|
6
|
+
end
|
7
|
+
|
8
|
+
def open_connection
|
9
|
+
return @connection if self.open?
|
10
|
+
|
11
|
+
# start a ractor if non running
|
12
|
+
unless EventMachine.reactor_running?
|
13
|
+
Thread.new do
|
14
|
+
EventMachine.run
|
15
|
+
end
|
16
|
+
|
17
|
+
AMQP::Hermes.wait_for(EventMachine, :reactor_running?)
|
18
|
+
end
|
19
|
+
|
20
|
+
@connection = AMQP.connect
|
21
|
+
end
|
22
|
+
|
23
|
+
def open?
|
24
|
+
EventMachine.reactor_running? && !@connection.nil?
|
25
|
+
end
|
26
|
+
|
27
|
+
def channel
|
28
|
+
@channel || open_channel
|
29
|
+
end
|
30
|
+
|
31
|
+
def open_channel
|
32
|
+
@channel = AMQP::Channel.new(self.connection)
|
33
|
+
end
|
34
|
+
|
35
|
+
def close
|
36
|
+
return if !open?
|
37
|
+
|
38
|
+
@connection.close
|
39
|
+
|
40
|
+
AMQP.stop do
|
41
|
+
EventMachine.stop
|
42
|
+
end
|
43
|
+
|
44
|
+
@connection = nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module AMQP
|
2
|
+
module Hermes
|
3
|
+
class Receiver
|
4
|
+
include AMQP::Hermes::Connectivity
|
5
|
+
|
6
|
+
attr_reader :messages, :queue, :exchange, :routing_key
|
7
|
+
attr_accessor :_listening
|
8
|
+
|
9
|
+
def initialize(queue, topic="pub/sub", options={})
|
10
|
+
raise "You *MUST* specify a queue" if queue.nil? or queue.empty?
|
11
|
+
@queue = queue
|
12
|
+
|
13
|
+
if topic.is_a? Hash
|
14
|
+
options = topic.dup
|
15
|
+
topic = options.delete(:topic) || "pub/sub"
|
16
|
+
end
|
17
|
+
|
18
|
+
@routing_key = options.delete(:routing_key)
|
19
|
+
@routing_key ||= "#{queue}.*"
|
20
|
+
|
21
|
+
if @routing_key !~ Regexp.new(queue)
|
22
|
+
@routing_key = "#{queue}.routing_key"
|
23
|
+
end
|
24
|
+
|
25
|
+
@handler = options.delete(:handler) || self
|
26
|
+
|
27
|
+
options[:auto_delete] ||= true
|
28
|
+
@exchange = channel.topic(topic, options)
|
29
|
+
|
30
|
+
@messages = []
|
31
|
+
@_listening = false
|
32
|
+
|
33
|
+
self.open_connection
|
34
|
+
self.listen
|
35
|
+
end
|
36
|
+
|
37
|
+
def listen
|
38
|
+
Thread.new(self, @handler) do |receiver, handler|
|
39
|
+
receiver._listening = true
|
40
|
+
|
41
|
+
receiver.channel.queue(receiver.queue).bind(
|
42
|
+
receiver.exchange, :routing_key => receiver.routing_key
|
43
|
+
).subscribe do |headers, payload|
|
44
|
+
handler.receive(AMQP::Hermes::Message.new(headers, payload))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def listening?
|
50
|
+
@_listening == true ? true : false
|
51
|
+
end
|
52
|
+
|
53
|
+
# implement the handler interface
|
54
|
+
def receive(message)
|
55
|
+
return nil if !message.kind_of?(AMQP::Hermes::Message)
|
56
|
+
@messages << message
|
57
|
+
end
|
58
|
+
|
59
|
+
def clear
|
60
|
+
@messages = []
|
61
|
+
end
|
62
|
+
|
63
|
+
def inspect
|
64
|
+
%Q{#<Hermes::Receiver @queue="#{@queue}" @routing_key="#{@routing_key}" @exchange="#{@exchange}" open=#{self.open?} listening=#{self.listening?}>}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module AMQP
|
2
|
+
module Hermes
|
3
|
+
class Transmitter
|
4
|
+
include AMQP::Hermes::Connectivity
|
5
|
+
|
6
|
+
attr_reader :queue
|
7
|
+
def initialize(queue=nil, topic="pub/sub", options={})
|
8
|
+
@queue = queue
|
9
|
+
|
10
|
+
options[:auto_delete] ||= true
|
11
|
+
@exchange = channel.topic(topic, options)
|
12
|
+
@transmitting = false
|
13
|
+
end
|
14
|
+
|
15
|
+
def transmit(payload, options={})
|
16
|
+
@transmitting = true
|
17
|
+
|
18
|
+
options.merge!(
|
19
|
+
:routing_key => @queue
|
20
|
+
) unless options.has_key?(:routing_key)
|
21
|
+
|
22
|
+
@exchange.publish( payload, options ) do
|
23
|
+
@transmitting = false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def done_transmitting?
|
28
|
+
@transmitting == true ? false : true
|
29
|
+
end
|
30
|
+
|
31
|
+
def close
|
32
|
+
AMQP::Hermes.wait_for(self, :done_transmitting?)
|
33
|
+
super
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AMQP::Hermes::Connectivity do
|
4
|
+
before :each do
|
5
|
+
@subject = Class.new
|
6
|
+
@subject.extend(AMQP::Hermes::Connectivity)
|
7
|
+
end
|
8
|
+
|
9
|
+
after :each do
|
10
|
+
@subject.close
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should have an open connection" do
|
14
|
+
@subject.connection.should_not be_nil
|
15
|
+
@subject.should be_open
|
16
|
+
@subject.connection.should be_kind_of(AMQP::Session)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should have an open channel" do
|
20
|
+
@subject.channel.should_not be_nil
|
21
|
+
@subject.channel.should be_kind_of(AMQP::Channel)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should close" do
|
25
|
+
@subject.open_connection
|
26
|
+
@subject.should be_open
|
27
|
+
|
28
|
+
@subject.close
|
29
|
+
|
30
|
+
@subject.should_not be_open
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class CustomHandler
|
4
|
+
def received?
|
5
|
+
@received == true ? true : false
|
6
|
+
end
|
7
|
+
def receive(message)
|
8
|
+
@received = true
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe CustomHandler do
|
13
|
+
it "should be a working alternate handler" do
|
14
|
+
handler = CustomHandler.new
|
15
|
+
handler.should_not be_received
|
16
|
+
|
17
|
+
handler.receive(AMQP::Hermes::Message.new("crud", "crud"))
|
18
|
+
handler.should be_received
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe AMQP::Hermes::Receiver do
|
23
|
+
before :each do
|
24
|
+
@receiver = AMQP::Hermes::Receiver.new("test.queue")
|
25
|
+
AMQP::Hermes.wait_for(@receiver, :listening?)
|
26
|
+
@receiver.clear
|
27
|
+
end
|
28
|
+
|
29
|
+
after :each do
|
30
|
+
@receiver.close
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should include connectivity" do
|
34
|
+
@receiver.should be_kind_of(AMQP::Hermes::Connectivity)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should set a default routing key" do
|
38
|
+
@receiver.routing_key.should == "test.queue.*"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should set a default handler" do
|
42
|
+
@receiver.instance_variable_get(:@handler).should == @receiver
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should open an exchange" do
|
46
|
+
@receiver.exchange.should_not be_nil
|
47
|
+
@receiver.exchange.should be_kind_of(AMQP::Exchange)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should be listening" do
|
51
|
+
@receiver.should be_listening
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should implement a handler interface" do
|
55
|
+
@receiver.messages.should be_empty
|
56
|
+
transmitter = AMQP::Hermes::Transmitter.new("test.queue.test")
|
57
|
+
transmitter.transmit "crud"
|
58
|
+
|
59
|
+
AMQP::Hermes.wait_for(@receiver.messages, :any?)
|
60
|
+
@receiver.messages.should be_any
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should accept an alternate handler" do
|
64
|
+
handler = CustomHandler.new
|
65
|
+
|
66
|
+
@receiver.close
|
67
|
+
@receiver = AMQP::Hermes::Receiver.new("test.queue", :handler => handler)
|
68
|
+
|
69
|
+
@receiver.instance_variable_get(:@handler).should == handler
|
70
|
+
|
71
|
+
AMQP::Hermes.wait_for(@receiver, :listening?)
|
72
|
+
|
73
|
+
transmitter = AMQP::Hermes::Transmitter.new("test.queue.test")
|
74
|
+
transmitter.transmit "crud"
|
75
|
+
|
76
|
+
AMQP::Hermes.wait_for(handler, :received?)
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AMQP::Hermes::Transmitter do
|
4
|
+
before :each do
|
5
|
+
@transmitter = AMQP::Hermes::Transmitter.new("test.queue.test")
|
6
|
+
@receiver = AMQP::Hermes::Receiver.new("test.queue")
|
7
|
+
|
8
|
+
AMQP::Hermes.wait_for(@receiver, :listening?)
|
9
|
+
@receiver.clear
|
10
|
+
end
|
11
|
+
|
12
|
+
after :each do
|
13
|
+
@receiver.close
|
14
|
+
@transmitter.close
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should include connectivity" do
|
18
|
+
@transmitter.should be_kind_of(AMQP::Hermes::Connectivity)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should hold a default queue" do
|
22
|
+
@transmitter.queue.should == "test.queue.test"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should transmitt messages on the default queue" do
|
26
|
+
message = Faker::Lorem.sentence
|
27
|
+
@transmitter.transmit message
|
28
|
+
|
29
|
+
AMQP::Hermes.wait_for(@receiver.messages, :any?)
|
30
|
+
|
31
|
+
@receiver.messages.collect(&:payload).should include(message)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should transmitt messages on a given queue" do
|
35
|
+
message = Faker::Lorem.sentence
|
36
|
+
@transmitter.transmit(message, :routing_key => "test.queue.given")
|
37
|
+
|
38
|
+
AMQP::Hermes.wait_for(@receiver.messages, :any?)
|
39
|
+
|
40
|
+
@receiver.messages.collect(&:payload).should include(message)
|
41
|
+
@receiver.messages.collect(&:headers).collect(&:routing_key).should include("test.queue.given")
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should accept AMQP options" do
|
45
|
+
message = Faker::Lorem.sentence
|
46
|
+
@transmitter.transmit(message, :mandatory => true, :persistent => true)
|
47
|
+
|
48
|
+
AMQP::Hermes.wait_for(@receiver.messages, :any?)
|
49
|
+
|
50
|
+
@receiver.messages.collect(&:payload).should include(message)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should let know it's done transmitting" do
|
54
|
+
message = Faker::Lorem.paragraph
|
55
|
+
@transmitter.transmit(message, :mandatory => true, :persistent => true)
|
56
|
+
@transmitter.should_not be_done_transmitting
|
57
|
+
end
|
58
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'amqp-hermes'
|
5
|
+
require 'faker'
|
6
|
+
|
7
|
+
# Requires supporting files with custom matchers and macros, etc,
|
8
|
+
# in ./support/ and its subdirectories.
|
9
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: amqp-hermes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 1.0.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Hartog C. de Mik
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-03-01 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: amqp
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0.9"
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rspec
|
28
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.8.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: faker
|
39
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "1"
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rdoc
|
50
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "3.12"
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: bundler
|
61
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ~>
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 1.0.0
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *id005
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: jeweler
|
72
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.8.3
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *id006
|
81
|
+
description: Wrapper around ruby-amqp to make pub/sub easier
|
82
|
+
email: hartog.de.mik@gmail.com
|
83
|
+
executables: []
|
84
|
+
|
85
|
+
extensions: []
|
86
|
+
|
87
|
+
extra_rdoc_files:
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.rdoc
|
90
|
+
files:
|
91
|
+
- .document
|
92
|
+
- .rspec
|
93
|
+
- Gemfile
|
94
|
+
- Gemfile.lock
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.rdoc
|
97
|
+
- Rakefile
|
98
|
+
- VERSION
|
99
|
+
- lib/amqp-hermes.rb
|
100
|
+
- lib/amqp-hermes/connectivity.rb
|
101
|
+
- lib/amqp-hermes/message.rb
|
102
|
+
- lib/amqp-hermes/receiver.rb
|
103
|
+
- lib/amqp-hermes/transmitter.rb
|
104
|
+
- lib/amqp-hermes/version.rb
|
105
|
+
- spec/amqp-hermes/connectivity_spec.rb
|
106
|
+
- spec/amqp-hermes/receiver_spec.rb
|
107
|
+
- spec/amqp-hermes/transmitter_spec.rb
|
108
|
+
- spec/spec_helper.rb
|
109
|
+
homepage: http://github.com/wyngle/amqp-hermes
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
hash: -1570954477034988232
|
123
|
+
segments:
|
124
|
+
- 0
|
125
|
+
version: "0"
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: "0"
|
132
|
+
requirements: []
|
133
|
+
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 1.8.16
|
136
|
+
signing_key:
|
137
|
+
specification_version: 3
|
138
|
+
summary: Hermes; Messenger of the gods
|
139
|
+
test_files: []
|
140
|
+
|