warren 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1 -0
- data/Manifest +2 -0
- data/Rakefile +1 -1
- data/lib/warren/adapters/bunny_adapter.rb +25 -5
- data/lib/warren/adapters/test_adapter.rb +1 -1
- data/lib/warren/filters/shared_secret.rb +1 -1
- data/spec/warren/adapters/bunny_adapter_spec.rb +93 -0
- data/spec/warren/adapters/test_adapter_spec.rb +5 -0
- data/warren.gemspec +6 -6
- metadata +4 -3
data/CHANGELOG
CHANGED
data/Manifest
CHANGED
@@ -23,9 +23,11 @@ lib/warren/queue.rb
|
|
23
23
|
readme.rdoc
|
24
24
|
spec/spec.opts
|
25
25
|
spec/spec_helper.rb
|
26
|
+
spec/warren/adapters/bunny_adapter_spec.rb
|
26
27
|
spec/warren/adapters/test_adapter_spec.rb
|
27
28
|
spec/warren/connection_spec.rb
|
28
29
|
spec/warren/queue_spec.rb
|
29
30
|
spec/warren/warren_spec.rb
|
30
31
|
tasks/rdoc.rake
|
31
32
|
tasks/rspec.rake
|
33
|
+
warren.gemspec
|
data/Rakefile
CHANGED
@@ -13,7 +13,7 @@ Echoe.new('warren') do | gem |
|
|
13
13
|
gem.email = 'support@brightbox.co.uk'
|
14
14
|
gem.summary = 'Library for pushing messages onto and off RabbitMQ queues'
|
15
15
|
gem.url = 'http://github.com/brightbox/warren'
|
16
|
-
gem.dependencies = [["amqp", '>= 0.6.0'], ["bunny", ">= 0.
|
16
|
+
gem.dependencies = [["amqp", '>= 0.6.0'], ["bunny", ">= 0.6.0"]]
|
17
17
|
end
|
18
18
|
|
19
19
|
desc "Generates the manifest and the gemspec"
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "rubygems"
|
2
|
+
gem "bunny", ">= 0.6.0"
|
2
3
|
require "bunny"
|
3
4
|
|
4
5
|
module Warren
|
@@ -10,8 +11,10 @@ module Warren
|
|
10
11
|
#
|
11
12
|
def self.check_connection_details opts
|
12
13
|
# Check they've passed in the stuff without a default on it
|
13
|
-
|
14
|
-
|
14
|
+
[:user, :pass, :vhost].each do | required_arg |
|
15
|
+
unless opts.has_key?(required_arg)
|
16
|
+
raise Warren::Connection::InvalidConnectionDetails, "#{required_arg.to_s.capitalize} not specified"
|
17
|
+
end
|
15
18
|
end
|
16
19
|
true
|
17
20
|
end
|
@@ -58,19 +61,36 @@ module Warren
|
|
58
61
|
#
|
59
62
|
# Expects a block and raises NoBlockGiven if no block is given.
|
60
63
|
#
|
64
|
+
# The block is passed up to two arguments, depending on how many
|
65
|
+
# you ask for. The first one is always required, which is the message
|
66
|
+
# passed over the queue (after being unpacked by filters.)
|
67
|
+
# The (optional) second argument is a hash of headers bunny gives us
|
68
|
+
# containing extra data about the message.
|
69
|
+
#
|
70
|
+
# Warren::Queue.subscribe(:default) {|msg, payload| puts msg, payload }
|
71
|
+
#
|
61
72
|
def self.subscribe queue_name, &block
|
62
73
|
raise NoBlockGiven unless block_given?
|
63
74
|
queue_name = self.queue_name if queue_name == :default
|
64
75
|
# todo: check if its a valid queue?
|
65
76
|
do_connect(queue_name) do |queue|
|
66
|
-
|
67
|
-
return if msg == :queue_empty
|
68
|
-
block.call(Warren::MessageFilter.unpack(msg))
|
77
|
+
handle_bunny_message(queue.pop, &block)
|
69
78
|
end
|
70
79
|
end
|
71
80
|
|
72
81
|
private
|
73
82
|
|
83
|
+
# Called when a message is pulled off the queue by bunny.
|
84
|
+
#
|
85
|
+
def self.handle_bunny_message headers, &block
|
86
|
+
payload = headers.delete(:payload)
|
87
|
+
return if payload == :queue_empty
|
88
|
+
# unpack it
|
89
|
+
payload = Warren::MessageFilter.unpack(payload)
|
90
|
+
# Call our block with as many args as we need to
|
91
|
+
block.arity == 1 ? block.call(payload) : block.call(payload, headers)
|
92
|
+
end
|
93
|
+
|
74
94
|
#
|
75
95
|
# Connects and does the stuff its told to!
|
76
96
|
#
|
@@ -18,7 +18,7 @@ module Warren
|
|
18
18
|
# Make sure both the publisher and subscriber use the same
|
19
19
|
# key else you'll get KeyValidationError error raised.
|
20
20
|
#
|
21
|
-
class SharedSecret
|
21
|
+
class SharedSecret < MessageFilter
|
22
22
|
# Raised when no key (salt) is provided
|
23
23
|
class NoKeyError < Exception; end
|
24
24
|
# Raised when there is a key mismatch error
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
require "#{File.dirname(__FILE__)}/../../../lib/warren/adapters/bunny_adapter.rb"
|
3
|
+
|
4
|
+
describe Warren::Queue::BunnyAdapter do
|
5
|
+
|
6
|
+
before do
|
7
|
+
# play nicely with other adapters loaded
|
8
|
+
Warren::Queue.adapter = Warren::Queue::BunnyAdapter
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "connection details" do
|
12
|
+
|
13
|
+
before do
|
14
|
+
setup_config_object
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should override check_connection_details" do
|
18
|
+
Warren::Queue::BunnyAdapter.methods(false).should include("check_connection_details")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should require a username" do
|
22
|
+
@options.delete(:user)
|
23
|
+
lambda {
|
24
|
+
Warren::Connection.new(@config)
|
25
|
+
}.should raise_error(Warren::Connection::InvalidConnectionDetails, "User not specified")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should require a password" do
|
29
|
+
@options.delete(:pass)
|
30
|
+
lambda {
|
31
|
+
Warren::Connection.new(@config)
|
32
|
+
}.should raise_error(Warren::Connection::InvalidConnectionDetails, "Pass not specified")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should require a vhost" do
|
36
|
+
@options.delete(:vhost)
|
37
|
+
lambda {
|
38
|
+
Warren::Connection.new(@config)
|
39
|
+
}.should raise_error(Warren::Connection::InvalidConnectionDetails, "Vhost not specified")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "subscribe" do
|
44
|
+
it "should override subscribe" do
|
45
|
+
Warren::Queue::BunnyAdapter.methods(false).should include("subscribe")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should accept a subscribe block with one argument" do
|
49
|
+
blk = lambda do |one|
|
50
|
+
one.should == "my message"
|
51
|
+
end
|
52
|
+
|
53
|
+
send_headers_to_bunny_with &blk
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should accept a subscribe block with two arguments" do
|
57
|
+
blk = lambda do | message, headers |
|
58
|
+
message.should == "my message"
|
59
|
+
headers.should == {:some => :header}
|
60
|
+
end
|
61
|
+
|
62
|
+
headers = {
|
63
|
+
:payload => "my message",
|
64
|
+
:some => :header
|
65
|
+
}
|
66
|
+
Warren::Queue::BunnyAdapter.__send__(:handle_bunny_message, headers, &blk)
|
67
|
+
end
|
68
|
+
|
69
|
+
def send_headers_to_bunny_with &blk
|
70
|
+
headers = {
|
71
|
+
:payload => "my message",
|
72
|
+
:some => :header
|
73
|
+
}
|
74
|
+
Warren::Queue::BunnyAdapter.__send__(:handle_bunny_message, headers, &blk)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
protected
|
79
|
+
|
80
|
+
def setup_config_object
|
81
|
+
@options = {
|
82
|
+
:host => "localhost",
|
83
|
+
:user => "rspec",
|
84
|
+
:pass => "password",
|
85
|
+
:vhost => "/",
|
86
|
+
:logging => false
|
87
|
+
}
|
88
|
+
@config = {
|
89
|
+
:development => @options
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
@@ -3,6 +3,11 @@ require "#{File.dirname(__FILE__)}/../../../lib/warren/adapters/test_adapter.rb"
|
|
3
3
|
|
4
4
|
describe TestAdapter do
|
5
5
|
|
6
|
+
before do
|
7
|
+
# play nicely with other adapters loaded
|
8
|
+
Warren::Queue.adapter = TestAdapter
|
9
|
+
end
|
10
|
+
|
6
11
|
before(:all) do
|
7
12
|
@file_name = "#{WARREN_ROOT}/tmp/warren.txt"
|
8
13
|
end
|
data/warren.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{warren}
|
5
|
-
s.version = "0.9.
|
5
|
+
s.version = "0.9.2"
|
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-12-21}
|
10
10
|
s.description = %q{Library for pushing messages onto and off RabbitMQ queues}
|
11
11
|
s.email = %q{support@brightbox.co.uk}
|
12
12
|
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "lib/warren.rb", "lib/warren/adapters/amqp_adapter.rb", "lib/warren/adapters/bunny_adapter.rb", "lib/warren/adapters/dummy_adapter.rb", "lib/warren/adapters/test_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", "tasks/rdoc.rake", "tasks/rspec.rake"]
|
13
|
-
s.files = ["CHANGELOG", "LICENSE", "Manifest", "Rakefile", "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.rb", "lib/warren/adapters/amqp_adapter.rb", "lib/warren/adapters/bunny_adapter.rb", "lib/warren/adapters/dummy_adapter.rb", "lib/warren/adapters/test_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", "readme.rdoc", "spec/spec.opts", "spec/spec_helper.rb", "spec/warren/adapters/test_adapter_spec.rb", "spec/warren/connection_spec.rb", "spec/warren/queue_spec.rb", "spec/warren/warren_spec.rb", "tasks/rdoc.rake", "tasks/rspec.rake", "warren.gemspec"]
|
13
|
+
s.files = ["CHANGELOG", "LICENSE", "Manifest", "Rakefile", "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.rb", "lib/warren/adapters/amqp_adapter.rb", "lib/warren/adapters/bunny_adapter.rb", "lib/warren/adapters/dummy_adapter.rb", "lib/warren/adapters/test_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", "readme.rdoc", "spec/spec.opts", "spec/spec_helper.rb", "spec/warren/adapters/bunny_adapter_spec.rb", "spec/warren/adapters/test_adapter_spec.rb", "spec/warren/connection_spec.rb", "spec/warren/queue_spec.rb", "spec/warren/warren_spec.rb", "tasks/rdoc.rake", "tasks/rspec.rake", "warren.gemspec"]
|
14
14
|
s.homepage = %q{http://github.com/brightbox/warren}
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Warren", "--main", "readme.rdoc"]
|
16
16
|
s.require_paths = ["lib"]
|
@@ -24,13 +24,13 @@ Gem::Specification.new do |s|
|
|
24
24
|
|
25
25
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
26
26
|
s.add_runtime_dependency(%q<amqp>, [">= 0.6.0"])
|
27
|
-
s.add_runtime_dependency(%q<bunny>, [">= 0.
|
27
|
+
s.add_runtime_dependency(%q<bunny>, [">= 0.6.0"])
|
28
28
|
else
|
29
29
|
s.add_dependency(%q<amqp>, [">= 0.6.0"])
|
30
|
-
s.add_dependency(%q<bunny>, [">= 0.
|
30
|
+
s.add_dependency(%q<bunny>, [">= 0.6.0"])
|
31
31
|
end
|
32
32
|
else
|
33
33
|
s.add_dependency(%q<amqp>, [">= 0.6.0"])
|
34
|
-
s.add_dependency(%q<bunny>, [">= 0.
|
34
|
+
s.add_dependency(%q<bunny>, [">= 0.6.0"])
|
35
35
|
end
|
36
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: warren
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
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-12-21 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.6.0
|
34
34
|
version:
|
35
35
|
description: Library for pushing messages onto and off RabbitMQ queues
|
36
36
|
email: support@brightbox.co.uk
|
@@ -79,6 +79,7 @@ files:
|
|
79
79
|
- readme.rdoc
|
80
80
|
- spec/spec.opts
|
81
81
|
- spec/spec_helper.rb
|
82
|
+
- spec/warren/adapters/bunny_adapter_spec.rb
|
82
83
|
- spec/warren/adapters/test_adapter_spec.rb
|
83
84
|
- spec/warren/connection_spec.rb
|
84
85
|
- spec/warren/queue_spec.rb
|