brightbox-warren 0.5 → 0.7
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.
- data/CHANGELOG +2 -0
- data/{LICENCE → LICENSE} +3 -3
- data/Manifest +12 -8
- data/Rakefile +2 -2
- data/examples/authed/receiver.rb +3 -1
- data/examples/authed/sender.rb +4 -2
- data/examples/simple/{mass_sender.rb → amqp_mass_sender.rb} +0 -0
- data/examples/simple/amqp_receiver.rb +18 -0
- data/examples/simple/{sender.rb → amqp_sender.rb} +7 -4
- data/examples/simple/bunny_receiver.rb +18 -0
- data/examples/simple/bunny_sender.rb +36 -0
- data/lib/warren.rb +8 -9
- data/lib/warren/adapters/amqp_adapter.rb +87 -0
- data/lib/warren/adapters/bunny_adapter.rb +97 -0
- data/lib/warren/connection.rb +56 -34
- data/lib/warren/{message_filters → filters}/shared_secret.rb +12 -12
- data/lib/warren/{message_filters → filters}/yaml.rb +3 -3
- data/lib/warren/message_filter.rb +21 -15
- data/lib/warren/queue.rb +47 -63
- data/readme.rdoc +16 -9
- data/spec/spec_helper.rb +0 -3
- data/spec/warren/connection_spec.rb +65 -46
- data/spec/warren/queue_spec.rb +58 -78
- data/spec/warren/warren_spec.rb +9 -0
- data/warren.gemspec +6 -7
- metadata +20 -14
- data/examples/simple/receiver.rb +0 -17
- data/spec/hash_extend.rb +0 -9
- data/spec/warren/message_filter_spec.rb +0 -84
data/spec/warren/queue_spec.rb
CHANGED
@@ -2,92 +2,72 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
2
|
|
3
3
|
describe Warren::Queue do
|
4
4
|
|
5
|
-
|
6
|
-
lambda {
|
7
|
-
Warren::Queue.connection
|
8
|
-
}.should raise_error(Warren::Queue::NoConnectionDetails)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should require connection details to publish" do
|
12
|
-
lambda {
|
13
|
-
Warren::Queue.publish("", "")
|
14
|
-
}.should raise_error(Warren::Queue::NoConnectionDetails)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should require connection details to subscribe" do
|
18
|
-
lambda {
|
19
|
-
Warren::Queue.subscribe("") { true }
|
20
|
-
}.should raise_error(Warren::Queue::NoConnectionDetails)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should set connection details" do
|
24
|
-
conn = new_connection
|
25
|
-
|
26
|
-
Warren::Queue.connection = conn
|
27
|
-
Warren::Queue.connection.should == conn
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should publish to a queue" do
|
31
|
-
Warren::Queue.connection = new_connection
|
32
|
-
|
33
|
-
Warren::Queue.should_receive(:do_connect).with(true, nil).and_return(true)
|
34
|
-
Warren::Queue.publish("queue", "payload")
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should publish to a default queue" do
|
38
|
-
Warren::Queue.connection = new_connection(:default_queue => "queue")
|
5
|
+
describe "connection" do
|
39
6
|
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should publish to a queue with a block" do
|
45
|
-
Warren::Queue.connection = new_connection
|
46
|
-
|
47
|
-
blk = Proc.new { true }
|
48
|
-
|
49
|
-
Warren::Queue.should_receive(:do_connect).with(true, blk).and_return(true)
|
50
|
-
Warren::Queue.publish("queue", "payload", &blk)
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "subscribing" do
|
54
|
-
|
55
|
-
it "should require a block to be passed" do
|
56
|
-
Warren::Queue.connection = new_connection
|
57
|
-
|
58
|
-
lambda {
|
59
|
-
Warren::Queue.subscribe("queue")
|
60
|
-
}.should raise_error(Warren::Queue::NoBlockGiven)
|
7
|
+
before(:all) do
|
8
|
+
@conn = stub 'connection'
|
61
9
|
end
|
62
10
|
|
63
|
-
it "should
|
64
|
-
Warren::
|
11
|
+
it "should create a new Warren::Connection if one doesn't exist" do
|
12
|
+
Warren::Connection.should_receive(:new).and_return(@conn)
|
65
13
|
|
66
|
-
Warren::Queue.
|
67
|
-
Warren::Queue.subscribe("queue") { true }
|
14
|
+
Warren::Queue.connection.should == @conn
|
68
15
|
end
|
69
16
|
|
70
|
-
it "should
|
71
|
-
|
17
|
+
it "should only create a connection once" do
|
18
|
+
# Already created the connection object in the first it
|
19
|
+
Warren::Connection.should_not_receive(:new)
|
72
20
|
|
73
|
-
Warren::Queue.
|
74
|
-
Warren::Queue.
|
21
|
+
Warren::Queue.connection.should == @conn
|
22
|
+
Warren::Queue.connection.should == @conn
|
75
23
|
end
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
private
|
80
|
-
|
81
|
-
def new_connection opts = {}
|
82
|
-
Warren::Connection.new(details.merge(opts))
|
83
24
|
end
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
:
|
89
|
-
|
90
|
-
|
25
|
+
|
26
|
+
describe "adapter" do
|
27
|
+
|
28
|
+
before(:each) do
|
29
|
+
@adapter = mock 'adapter', :publish => "publish", :subscribe => "subscribe"
|
30
|
+
Warren::Queue.adapter = @adapter
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should have an adapter set" do
|
34
|
+
Warren::Queue.adapter.should == @adapter
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should pass publish through to the adapter" do
|
38
|
+
@adapter.should_receive(:publish)
|
39
|
+
Warren::Queue.publish.should == "publish"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should pass arguments through to adapter#publish" do
|
43
|
+
@adapter.should_receive(:publish).with("foo", "bar")
|
44
|
+
|
45
|
+
Warren::Queue.publish("foo", "bar").should == "publish"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should pass a block through to adapter#publish" do
|
49
|
+
block = lambda { true }
|
50
|
+
@adapter.should_receive(:publish).with("foo", "bar", block)
|
51
|
+
|
52
|
+
Warren::Queue.publish("foo", "bar", block).should == "publish"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should pass subscribe through to the adapter" do
|
56
|
+
@adapter.should_receive(:subscribe)
|
57
|
+
Warren::Queue.subscribe.should == "subscribe"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should pass arguments through to adapter#subscribe" do
|
61
|
+
@adapter.should_receive(:subscribe).with("foo", "bar")
|
62
|
+
|
63
|
+
Warren::Queue.subscribe("foo", "bar").should == "subscribe"
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should pass a block through to adapter#subscribe" do
|
67
|
+
block = lambda { true }
|
68
|
+
@adapter.should_receive(:subscribe).with("foo", "bar", block)
|
69
|
+
|
70
|
+
Warren::Queue.subscribe("foo", "bar", block).should == "subscribe"
|
71
|
+
end
|
91
72
|
end
|
92
|
-
|
93
73
|
end
|
data/warren.gemspec
CHANGED
@@ -2,26 +2,25 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{warren}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.7"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Caius Durling, David Smalley"]
|
9
|
-
s.date = %q{2009-
|
9
|
+
s.date = %q{2009-06-12}
|
10
10
|
s.description = %q{Library for pushing messages onto and off RabbitMQ queues}
|
11
11
|
s.email = %q{support@brightbox.co.uk}
|
12
|
-
s.extra_rdoc_files = ["CHANGELOG", "lib/warren/
|
13
|
-
s.files = ["CHANGELOG", "examples/authed/receiver.rb", "examples/authed/secret.rb", "examples/authed/sender.rb", "examples/simple/
|
14
|
-
s.has_rdoc = true
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "lib/warren/adapters/amqp_adapter.rb", "lib/warren/adapters/bunny_adapter.rb", "lib/warren/connection.rb", "lib/warren/filters/shared_secret.rb", "lib/warren/filters/yaml.rb", "lib/warren/message_filter.rb", "lib/warren/queue.rb", "lib/warren.rb", "LICENSE", "tasks/rdoc.rake", "tasks/rspec.rake"]
|
13
|
+
s.files = ["CHANGELOG", "examples/authed/receiver.rb", "examples/authed/secret.rb", "examples/authed/sender.rb", "examples/simple/amqp_mass_sender.rb", "examples/simple/amqp_receiver.rb", "examples/simple/amqp_sender.rb", "examples/simple/bunny_receiver.rb", "examples/simple/bunny_sender.rb", "lib/warren/adapters/amqp_adapter.rb", "lib/warren/adapters/bunny_adapter.rb", "lib/warren/connection.rb", "lib/warren/filters/shared_secret.rb", "lib/warren/filters/yaml.rb", "lib/warren/message_filter.rb", "lib/warren/queue.rb", "lib/warren.rb", "LICENSE", "Manifest", "Rakefile", "readme.rdoc", "spec/spec.opts", "spec/spec_helper.rb", "spec/warren/connection_spec.rb", "spec/warren/queue_spec.rb", "spec/warren/warren_spec.rb", "tasks/rdoc.rake", "tasks/rspec.rake", "warren.gemspec"]
|
15
14
|
s.homepage = %q{http://github.com/brightbox/warren}
|
16
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Warren", "--main", "readme.rdoc"]
|
17
16
|
s.require_paths = ["lib"]
|
18
17
|
s.rubyforge_project = %q{warren}
|
19
|
-
s.rubygems_version = %q{1.3.
|
18
|
+
s.rubygems_version = %q{1.3.4}
|
20
19
|
s.summary = %q{Library for pushing messages onto and off RabbitMQ queues}
|
21
20
|
|
22
21
|
if s.respond_to? :specification_version then
|
23
22
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
|
-
s.specification_version =
|
23
|
+
s.specification_version = 3
|
25
24
|
|
26
25
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
27
26
|
s.add_runtime_dependency(%q<amqp>, [">= 0.6.0"])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brightbox-warren
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.7"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Caius Durling, David Smalley
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-06-12 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -30,12 +30,15 @@ extensions: []
|
|
30
30
|
|
31
31
|
extra_rdoc_files:
|
32
32
|
- CHANGELOG
|
33
|
+
- lib/warren/adapters/amqp_adapter.rb
|
34
|
+
- lib/warren/adapters/bunny_adapter.rb
|
33
35
|
- lib/warren/connection.rb
|
36
|
+
- lib/warren/filters/shared_secret.rb
|
37
|
+
- lib/warren/filters/yaml.rb
|
34
38
|
- lib/warren/message_filter.rb
|
35
|
-
- lib/warren/message_filters/shared_secret.rb
|
36
|
-
- lib/warren/message_filters/yaml.rb
|
37
39
|
- lib/warren/queue.rb
|
38
40
|
- lib/warren.rb
|
41
|
+
- LICENSE
|
39
42
|
- tasks/rdoc.rake
|
40
43
|
- tasks/rspec.rake
|
41
44
|
files:
|
@@ -43,29 +46,32 @@ files:
|
|
43
46
|
- examples/authed/receiver.rb
|
44
47
|
- examples/authed/secret.rb
|
45
48
|
- examples/authed/sender.rb
|
46
|
-
- examples/simple/
|
47
|
-
- examples/simple/
|
48
|
-
- examples/simple/
|
49
|
+
- examples/simple/amqp_mass_sender.rb
|
50
|
+
- examples/simple/amqp_receiver.rb
|
51
|
+
- examples/simple/amqp_sender.rb
|
52
|
+
- examples/simple/bunny_receiver.rb
|
53
|
+
- examples/simple/bunny_sender.rb
|
54
|
+
- lib/warren/adapters/amqp_adapter.rb
|
55
|
+
- lib/warren/adapters/bunny_adapter.rb
|
49
56
|
- lib/warren/connection.rb
|
57
|
+
- lib/warren/filters/shared_secret.rb
|
58
|
+
- lib/warren/filters/yaml.rb
|
50
59
|
- lib/warren/message_filter.rb
|
51
|
-
- lib/warren/message_filters/shared_secret.rb
|
52
|
-
- lib/warren/message_filters/yaml.rb
|
53
60
|
- lib/warren/queue.rb
|
54
61
|
- lib/warren.rb
|
55
|
-
-
|
62
|
+
- LICENSE
|
56
63
|
- Manifest
|
57
64
|
- Rakefile
|
58
65
|
- readme.rdoc
|
59
|
-
- spec/hash_extend.rb
|
60
66
|
- spec/spec.opts
|
61
67
|
- spec/spec_helper.rb
|
62
68
|
- spec/warren/connection_spec.rb
|
63
|
-
- spec/warren/message_filter_spec.rb
|
64
69
|
- spec/warren/queue_spec.rb
|
70
|
+
- spec/warren/warren_spec.rb
|
65
71
|
- tasks/rdoc.rake
|
66
72
|
- tasks/rspec.rake
|
67
73
|
- warren.gemspec
|
68
|
-
has_rdoc:
|
74
|
+
has_rdoc: false
|
69
75
|
homepage: http://github.com/brightbox/warren
|
70
76
|
post_install_message:
|
71
77
|
rdoc_options:
|
@@ -94,7 +100,7 @@ requirements: []
|
|
94
100
|
rubyforge_project: warren
|
95
101
|
rubygems_version: 1.2.0
|
96
102
|
signing_key:
|
97
|
-
specification_version:
|
103
|
+
specification_version: 3
|
98
104
|
summary: Library for pushing messages onto and off RabbitMQ queues
|
99
105
|
test_files: []
|
100
106
|
|
data/examples/simple/receiver.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + "/../lib/warren")
|
3
|
-
|
4
|
-
Signal.trap("INT") { AMQP.stop { EM.stop } }
|
5
|
-
Signal.trap("TERM") { AMQP.stop { EM.stop } }
|
6
|
-
|
7
|
-
# Listen to the main queue
|
8
|
-
q = "main"
|
9
|
-
puts "Listening to the #{q} queue."
|
10
|
-
|
11
|
-
# Setup the connection directly this time
|
12
|
-
Warren::Queue.connection = {:user => "caius", :pass => "caius", :vhost => "/"}
|
13
|
-
|
14
|
-
# And attach a block for new messages to fire
|
15
|
-
Warren::Queue.subscribe(q) do |msg|
|
16
|
-
p [Time.now, msg]
|
17
|
-
end
|
data/spec/hash_extend.rb
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
|
-
# Needed for some tests later on
|
4
|
-
class Foo
|
5
|
-
def self.pack msg
|
6
|
-
msg
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.unpack msg
|
10
|
-
msg
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe Warren::MessageFilter do
|
15
|
-
|
16
|
-
before(:each) do
|
17
|
-
Warren::MessageFilter.reset_filters
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "Managing Filters" do
|
21
|
-
it "should have YAML as a filter by default" do
|
22
|
-
fs = Warren::MessageFilter.filters
|
23
|
-
|
24
|
-
fs.should have(1).element
|
25
|
-
fs.first.should == Warren::MessageFilter::Yaml
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should add additional filters to the stack" do
|
29
|
-
Warren::MessageFilter.should respond_to(:<<)
|
30
|
-
Warren::MessageFilter << Foo
|
31
|
-
fs = Warren::MessageFilter.filters
|
32
|
-
|
33
|
-
fs.should have(2).elements
|
34
|
-
fs.first.should == Warren::MessageFilter::Yaml
|
35
|
-
fs.last.should == Foo
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe "calling filters to send message" do
|
40
|
-
|
41
|
-
it "should YAML by default" do
|
42
|
-
@msg = "message"
|
43
|
-
Warren::MessageFilter::Yaml.should_receive(:pack).with(@msg).and_return("yamled")
|
44
|
-
|
45
|
-
Warren::MessageFilter.pack(@msg)
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should call each filter in turn when packing" do
|
49
|
-
@msg = "message"
|
50
|
-
|
51
|
-
Foo.should_receive(:pack).with(@msg).and_return("fooed")
|
52
|
-
Warren::MessageFilter::Yaml.should_receive(:pack).with("fooed").and_return("yamled")
|
53
|
-
|
54
|
-
Warren::MessageFilter << Foo
|
55
|
-
|
56
|
-
Warren::MessageFilter.pack(@msg).should == "yamled"
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "calling filters to unpack message" do
|
62
|
-
it "should un-YAML by default" do
|
63
|
-
@msg = "yamled"
|
64
|
-
|
65
|
-
Warren::MessageFilter::Yaml.should_receive(:unpack).with("yamled").and_return("message")
|
66
|
-
|
67
|
-
Warren::MessageFilter.unpack(@msg).should == "message"
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should run all unpack filters" do
|
71
|
-
@msg = "yamled message"
|
72
|
-
|
73
|
-
Warren::MessageFilter::Yaml.should_receive(:unpack).with("yamled message").and_return("fooed")
|
74
|
-
Foo.should_receive(:unpack).with("fooed").and_return("message")
|
75
|
-
|
76
|
-
Warren::MessageFilter << Foo
|
77
|
-
Warren::MessageFilter.filters.should == [Warren::MessageFilter::Yaml, Foo]
|
78
|
-
|
79
|
-
Warren::MessageFilter.unpack(@msg).should == "message"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
end
|
84
|
-
|