roger_rabbit 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README +29 -0
- data/Rakefile +13 -0
- data/lib/roger_rabbit/version.rb +3 -0
- data/lib/roger_rabbit.rb +34 -0
- data/roger_rabbit.gemspec +25 -0
- data/test/test_roger_rabbit.rb +30 -0
- metadata +116 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'roger_rabbit'
|
4
|
+
|
5
|
+
class TestRogerRabbit < Test::Unit::TestCase
|
6
|
+
|
7
|
+
# You should have rabbitmq installed and running.
|
8
|
+
def test_it
|
9
|
+
queue_name = "test"
|
10
|
+
2.times do
|
11
|
+
RogerRabbit.publish queue_name, :joe => 'cool'
|
12
|
+
end
|
13
|
+
|
14
|
+
count = 0
|
15
|
+
|
16
|
+
# RogerRabbit.consume will loop forever, so we're
|
17
|
+
# going to break out of it with a Timeout.
|
18
|
+
assert_raises(Timeout::Error) do
|
19
|
+
Timeout.timeout(0.05) do
|
20
|
+
RogerRabbit.consume queue_name do |args|
|
21
|
+
assert_equal({ "joe" => 'cool' }, args)
|
22
|
+
count += 1
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
assert_equal 2, count, "we should have consumed 2 messages"
|
28
|
+
end
|
29
|
+
end
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'bundler'
|
5
|
+
|
6
|
+
Bundler::GemHelper.install_tasks
|
7
|
+
|
8
|
+
Rake::TestTask.new(:test) do |test|
|
9
|
+
test.libs << 'lib' << 'test'
|
10
|
+
test.pattern = 'test/**/test_*.rb'
|
11
|
+
end
|
12
|
+
|
13
|
+
task :default => :test
|
data/lib/roger_rabbit.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'bunny'
|
2
|
+
require 'json'
|
3
|
+
require 'active_support/hash_with_indifferent_access'
|
4
|
+
|
5
|
+
module RogerRabbit
|
6
|
+
def self.bunny
|
7
|
+
if ! @bunny
|
8
|
+
@bunny = Bunny.new
|
9
|
+
@bunny.start
|
10
|
+
@bunny.qos
|
11
|
+
end
|
12
|
+
@bunny
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.bunny_queue queue_name
|
16
|
+
@queues ||= {}
|
17
|
+
@queues[queue_name] ||= bunny.queue(queue_name)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.consume queue_name, &block
|
21
|
+
bunny_queue(queue_name).subscribe(:ack => true) do |msg|
|
22
|
+
begin
|
23
|
+
yield ActiveSupport::HashWithIndifferentAccess.new(JSON.parse(msg[:payload]))
|
24
|
+
rescue JSON::ParserError => e
|
25
|
+
puts e.message
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.publish queue_name, args
|
31
|
+
args = args.to_json
|
32
|
+
bunny_queue(queue_name).publish(args)
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "roger_rabbit/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "roger_rabbit"
|
7
|
+
s.version = RogerRabbit::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Joe Van Dyk"]
|
10
|
+
s.email = ["joe@tanga.com"]
|
11
|
+
s.homepage = "http://github.com/joevandyk/roger_rabbit"
|
12
|
+
s.summary = %q{Sweet wrapper around the bunny rabbitmq library}
|
13
|
+
s.description = %q{Sweet wrapper around the bunny rabbitmq library}
|
14
|
+
|
15
|
+
s.rubyforge_project = "roger_rabbit"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency "bunny"
|
23
|
+
s.add_dependency "json"
|
24
|
+
s.add_dependency "activesupport"
|
25
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'roger_rabbit'
|
4
|
+
|
5
|
+
class TestRogerRabbit < Test::Unit::TestCase
|
6
|
+
|
7
|
+
# You should have rabbitmq installed and running.
|
8
|
+
def test_it
|
9
|
+
queue_name = "test"
|
10
|
+
2.times do
|
11
|
+
RogerRabbit.publish queue_name, :joe => 'cool'
|
12
|
+
end
|
13
|
+
|
14
|
+
count = 0
|
15
|
+
|
16
|
+
# RogerRabbit.consume will loop forever, so we're
|
17
|
+
# going to break out of it with a Timeout.
|
18
|
+
assert_raises(Timeout::Error) do
|
19
|
+
Timeout.timeout(0.05) do
|
20
|
+
RogerRabbit.consume queue_name do |args|
|
21
|
+
assert_equal({ "joe" => 'cool' }, args)
|
22
|
+
assert_equal "cool", args[:joe] # Indifferent access
|
23
|
+
count += 1
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
assert_equal 2, count, "we should have consumed 2 messages"
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: roger_rabbit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Joe Van Dyk
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-19 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: bunny
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: json
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: activesupport
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :runtime
|
62
|
+
version_requirements: *id003
|
63
|
+
description: Sweet wrapper around the bunny rabbitmq library
|
64
|
+
email:
|
65
|
+
- joe@tanga.com
|
66
|
+
executables: []
|
67
|
+
|
68
|
+
extensions: []
|
69
|
+
|
70
|
+
extra_rdoc_files: []
|
71
|
+
|
72
|
+
files:
|
73
|
+
- .gitignore
|
74
|
+
- Gemfile
|
75
|
+
- README
|
76
|
+
- Rakefile
|
77
|
+
- lib/roger_rabbit.rb
|
78
|
+
- lib/roger_rabbit/version.rb
|
79
|
+
- roger_rabbit.gemspec
|
80
|
+
- test/test_roger_rabbit.rb
|
81
|
+
has_rdoc: true
|
82
|
+
homepage: http://github.com/joevandyk/roger_rabbit
|
83
|
+
licenses: []
|
84
|
+
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
hash: 3
|
96
|
+
segments:
|
97
|
+
- 0
|
98
|
+
version: "0"
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
hash: 3
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
version: "0"
|
108
|
+
requirements: []
|
109
|
+
|
110
|
+
rubyforge_project: roger_rabbit
|
111
|
+
rubygems_version: 1.6.2
|
112
|
+
signing_key:
|
113
|
+
specification_version: 3
|
114
|
+
summary: Sweet wrapper around the bunny rabbitmq library
|
115
|
+
test_files: []
|
116
|
+
|