bugs_bunny 0.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/.document +5 -0
- data/.gitignore +22 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +58 -0
- data/VERSION +1 -0
- data/bin/bbunny +40 -0
- data/bugs_bunny.gemspec +78 -0
- data/cucumber.yml +1 -0
- data/features/bugs_bunny.feature +10 -0
- data/features/queues.feature +77 -0
- data/features/step_definitions/bugs_bunny_steps.rb +7 -0
- data/features/step_definitions/queue_steps.rb +20 -0
- data/features/support/env.rb +8 -0
- data/lib/bugs_bunny/cli.rb +66 -0
- data/lib/bugs_bunny/rabbit.rb +72 -0
- data/lib/bugs_bunny/rabbitmq.yml +7 -0
- data/lib/bugs_bunny/record.rb +114 -0
- data/lib/bugs_bunny.rb +17 -0
- data/spec/bugs_bunny/cli_spec.rb +19 -0
- data/spec/bugs_bunny/rabbit_spec.rb +12 -0
- data/spec/bugs_bunny_spec.rb +6 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- metadata +128 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2009 Marcos Piccinini
|
|
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,17 @@
|
|
|
1
|
+
= bugs_bunny
|
|
2
|
+
|
|
3
|
+
Description goes here.
|
|
4
|
+
|
|
5
|
+
== Note on Patches/Pull Requests
|
|
6
|
+
|
|
7
|
+
* Fork the project.
|
|
8
|
+
* Make your feature addition or bug fix.
|
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
|
10
|
+
future version unintentionally.
|
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
|
14
|
+
|
|
15
|
+
== Copyright
|
|
16
|
+
|
|
17
|
+
Copyright (c) 2010 Marcos Piccinini. See LICENSE for details.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake'
|
|
3
|
+
|
|
4
|
+
begin
|
|
5
|
+
require 'jeweler'
|
|
6
|
+
Jeweler::Tasks.new do |gem|
|
|
7
|
+
gem.name = "bugs_bunny"
|
|
8
|
+
gem.summary = "Play/Manage RabbitMQ"
|
|
9
|
+
gem.description = "Play/Manage RabbitMQ. Vhosts, queues."
|
|
10
|
+
gem.email = "x@nofxx.com"
|
|
11
|
+
gem.homepage = "http://github.com/nofxx/bugs_bunny"
|
|
12
|
+
gem.authors = ["Marcos Piccinini"]
|
|
13
|
+
|
|
14
|
+
gem.add_dependency "amqp", ">=0.6.7"
|
|
15
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
|
16
|
+
gem.add_development_dependency "cucumber", ">= 0"
|
|
17
|
+
end
|
|
18
|
+
Jeweler::GemcutterTasks.new
|
|
19
|
+
rescue LoadError
|
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
require 'spec/rake/spectask'
|
|
24
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
|
25
|
+
spec.libs << 'lib' << 'spec'
|
|
26
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
|
30
|
+
spec.libs << 'lib' << 'spec'
|
|
31
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
|
32
|
+
spec.rcov = true
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
task :spec => :check_dependencies
|
|
36
|
+
|
|
37
|
+
begin
|
|
38
|
+
require 'cucumber/rake/task'
|
|
39
|
+
Cucumber::Rake::Task.new(:features)
|
|
40
|
+
|
|
41
|
+
task :features => :check_dependencies
|
|
42
|
+
rescue LoadError
|
|
43
|
+
task :features do
|
|
44
|
+
abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
task :default => :spec
|
|
49
|
+
|
|
50
|
+
require 'rake/rdoctask'
|
|
51
|
+
Rake::RDocTask.new do |rdoc|
|
|
52
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
|
53
|
+
|
|
54
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
55
|
+
rdoc.title = "bugs_bunny #{version}"
|
|
56
|
+
rdoc.rdoc_files.include('README*')
|
|
57
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
58
|
+
end
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.0.7
|
data/bin/bbunny
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
3
|
+
require 'rubygems'
|
|
4
|
+
require 'optparse'
|
|
5
|
+
require 'bugs_bunny'
|
|
6
|
+
|
|
7
|
+
opt = OptionParser.new do |o|
|
|
8
|
+
o.banner = <<BANNER
|
|
9
|
+
Bugs Bunny - RabbitMQ Playground
|
|
10
|
+
|
|
11
|
+
Usage: #{File.basename($0)} command [args]
|
|
12
|
+
|
|
13
|
+
Commands:
|
|
14
|
+
|
|
15
|
+
vhosts - List vhosts
|
|
16
|
+
users - List and filter items
|
|
17
|
+
queues - Order by: name, price, store.
|
|
18
|
+
clear - Wipe out mnesia
|
|
19
|
+
config - "Generates a config file for AMQP connection
|
|
20
|
+
|
|
21
|
+
Common usage:
|
|
22
|
+
|
|
23
|
+
pyradise queue foo
|
|
24
|
+
|
|
25
|
+
Options:
|
|
26
|
+
|
|
27
|
+
BANNER
|
|
28
|
+
o.on('-c CONFIG', "Config file path") { |path| Opt[:config] = path }
|
|
29
|
+
o.on('-p PATH', "Output path for config file") { |path| Opt[:out] = path }
|
|
30
|
+
o.on('-v', "Verbose") { |b| Opt[:verbose] = true }
|
|
31
|
+
o.on('-f', "Force") { |b| Opt[:force] = true }
|
|
32
|
+
o.on('-h') { puts o; exit }
|
|
33
|
+
o.parse!
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
if ARGV.empty?
|
|
37
|
+
puts opt
|
|
38
|
+
else
|
|
39
|
+
BugsBunny::CLI.new(ARGV)
|
|
40
|
+
end
|
data/bugs_bunny.gemspec
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Generated by jeweler
|
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
|
4
|
+
# -*- encoding: utf-8 -*-
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |s|
|
|
7
|
+
s.name = %q{bugs_bunny}
|
|
8
|
+
s.version = "0.0.7"
|
|
9
|
+
|
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
|
+
s.authors = ["Marcos Piccinini"]
|
|
12
|
+
s.date = %q{2010-03-03}
|
|
13
|
+
s.default_executable = %q{bbunny}
|
|
14
|
+
s.description = %q{Play/Manage RabbitMQ. Vhosts, queues.}
|
|
15
|
+
s.email = %q{x@nofxx.com}
|
|
16
|
+
s.executables = ["bbunny"]
|
|
17
|
+
s.extra_rdoc_files = [
|
|
18
|
+
"LICENSE",
|
|
19
|
+
"README.rdoc"
|
|
20
|
+
]
|
|
21
|
+
s.files = [
|
|
22
|
+
".document",
|
|
23
|
+
".gitignore",
|
|
24
|
+
"LICENSE",
|
|
25
|
+
"README.rdoc",
|
|
26
|
+
"Rakefile",
|
|
27
|
+
"VERSION",
|
|
28
|
+
"bin/bbunny",
|
|
29
|
+
"bugs_bunny.gemspec",
|
|
30
|
+
"cucumber.yml",
|
|
31
|
+
"features/bugs_bunny.feature",
|
|
32
|
+
"features/queues.feature",
|
|
33
|
+
"features/step_definitions/bugs_bunny_steps.rb",
|
|
34
|
+
"features/step_definitions/queue_steps.rb",
|
|
35
|
+
"features/support/env.rb",
|
|
36
|
+
"lib/bugs_bunny.rb",
|
|
37
|
+
"lib/bugs_bunny/cli.rb",
|
|
38
|
+
"lib/bugs_bunny/rabbit.rb",
|
|
39
|
+
"lib/bugs_bunny/rabbitmq.yml",
|
|
40
|
+
"lib/bugs_bunny/record.rb",
|
|
41
|
+
"spec/bugs_bunny/cli_spec.rb",
|
|
42
|
+
"spec/bugs_bunny/rabbit_spec.rb",
|
|
43
|
+
"spec/bugs_bunny_spec.rb",
|
|
44
|
+
"spec/spec.opts",
|
|
45
|
+
"spec/spec_helper.rb"
|
|
46
|
+
]
|
|
47
|
+
s.homepage = %q{http://github.com/nofxx/bugs_bunny}
|
|
48
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
|
49
|
+
s.require_paths = ["lib"]
|
|
50
|
+
s.rubygems_version = %q{1.3.6}
|
|
51
|
+
s.summary = %q{Play/Manage RabbitMQ}
|
|
52
|
+
s.test_files = [
|
|
53
|
+
"spec/bugs_bunny/cli_spec.rb",
|
|
54
|
+
"spec/bugs_bunny/rabbit_spec.rb",
|
|
55
|
+
"spec/bugs_bunny_spec.rb",
|
|
56
|
+
"spec/spec_helper.rb"
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
if s.respond_to? :specification_version then
|
|
60
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
61
|
+
s.specification_version = 3
|
|
62
|
+
|
|
63
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
64
|
+
s.add_runtime_dependency(%q<amqp>, [">= 0.6.7"])
|
|
65
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
|
66
|
+
s.add_development_dependency(%q<cucumber>, [">= 0"])
|
|
67
|
+
else
|
|
68
|
+
s.add_dependency(%q<amqp>, [">= 0.6.7"])
|
|
69
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
|
70
|
+
s.add_dependency(%q<cucumber>, [">= 0"])
|
|
71
|
+
end
|
|
72
|
+
else
|
|
73
|
+
s.add_dependency(%q<amqp>, [">= 0.6.7"])
|
|
74
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
|
75
|
+
s.add_dependency(%q<cucumber>, [">= 0"])
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
data/cucumber.yml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
default: -r features/support/env.rb -r features/step_definitions -r features
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
Feature: Managing queues
|
|
2
|
+
In order to manage queues
|
|
3
|
+
A user should have a nice command to do it
|
|
4
|
+
|
|
5
|
+
Scenario: Creating queues
|
|
6
|
+
Given I have no queues
|
|
7
|
+
When I run "queues new todo"
|
|
8
|
+
Then I should have 1 queues
|
|
9
|
+
When I run "queues"
|
|
10
|
+
Then I should see "todo"
|
|
11
|
+
And I should see "0 messages"
|
|
12
|
+
|
|
13
|
+
Scenario: Show queues
|
|
14
|
+
Given a queue "crucification" with 3 messages
|
|
15
|
+
When I run "queue crucification"
|
|
16
|
+
Then I should see "About crucification"
|
|
17
|
+
And I should see "3 messages, 0 consumers"
|
|
18
|
+
|
|
19
|
+
Scenario: List queues
|
|
20
|
+
Given I run "queues"
|
|
21
|
+
Then I should see "Queues"
|
|
22
|
+
And I should see "todo"
|
|
23
|
+
And I should see "crucification"
|
|
24
|
+
And I should see "0 messages"
|
|
25
|
+
And I should see "3 messages"
|
|
26
|
+
|
|
27
|
+
Scenario: Add to queue
|
|
28
|
+
Given a queue "works"
|
|
29
|
+
When I run "queue works add bugsbunny"
|
|
30
|
+
And I run "queue works"
|
|
31
|
+
Then I should see "About works"
|
|
32
|
+
And I should see "1 message"
|
|
33
|
+
When I run "queue works add bunny"
|
|
34
|
+
And I run "queue works"
|
|
35
|
+
Then I should see "About works"
|
|
36
|
+
And I should see "2 messages"
|
|
37
|
+
|
|
38
|
+
Scenario: Pop from queue
|
|
39
|
+
When I run "queue works pop"
|
|
40
|
+
Then I should see "Pop"
|
|
41
|
+
And I should see "bugsbunny"
|
|
42
|
+
And I run "queue works"
|
|
43
|
+
Then I should see "About works"
|
|
44
|
+
And I should see "1 messages"
|
|
45
|
+
When I run "queue works pop"
|
|
46
|
+
And I run "queue works"
|
|
47
|
+
And I should see "0 messages"
|
|
48
|
+
|
|
49
|
+
Scenario: List all messages
|
|
50
|
+
When I run "queue works add rock"
|
|
51
|
+
And I run "queue works add roll"
|
|
52
|
+
When I run "queue works list"
|
|
53
|
+
Then I should see "QUEUE 1"
|
|
54
|
+
And I should see "rock"
|
|
55
|
+
And I should see "Consumer: works"
|
|
56
|
+
And I should see "Exchange:"
|
|
57
|
+
And I should see "QUEUE 2"
|
|
58
|
+
And I should see "roll"
|
|
59
|
+
And I should see "Mode 1"
|
|
60
|
+
|
|
61
|
+
Scenario: Purging queue
|
|
62
|
+
When I run "queue works add more"
|
|
63
|
+
Then I run "queue works purge"
|
|
64
|
+
And I run "queue works"
|
|
65
|
+
And I should see "0 messages"
|
|
66
|
+
When I run "queue crucification"
|
|
67
|
+
Then I should see "3 messages"
|
|
68
|
+
|
|
69
|
+
Scenario: Purging queues
|
|
70
|
+
When I run "queue works add moreone"
|
|
71
|
+
And I run "queue works"
|
|
72
|
+
And I should see "1 message"
|
|
73
|
+
Then I run "queues purge"
|
|
74
|
+
And I run "queue works"
|
|
75
|
+
And I should see "0 messages"
|
|
76
|
+
When I run "queue crucification"
|
|
77
|
+
Then I should see "0 messages"
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
|
|
2
|
+
Given /^a queue "([^\"]*)" with (\d+) messages$/ do |name, n|
|
|
3
|
+
Given "I run \"queues new #{name}\""
|
|
4
|
+
n.to_i.times do |i|
|
|
5
|
+
Given "I run \"queue #{name} add Message#{i}\""
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
Given /^a queue "([^\"]*)"$/ do |name|
|
|
10
|
+
Given "I run \"queues new #{name}\""
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
Given /^I have no queues$/ do
|
|
14
|
+
Given 'I run "queues delete"'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
Then /^I should have (\d+) queues*$/ do |n|
|
|
18
|
+
Given 'I run "queues"'
|
|
19
|
+
@out.split("\n").length.should eql(n.to_i+1)
|
|
20
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Command Line Stuff
|
|
2
|
+
require 'yaml'
|
|
3
|
+
begin # Needed (really?) for ruby 1.8
|
|
4
|
+
# require 'ftools'
|
|
5
|
+
rescue LoadError
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
module BugsBunny
|
|
9
|
+
class CLI
|
|
10
|
+
CONFIG_FILE = "rabbitmq.yml"
|
|
11
|
+
|
|
12
|
+
def initialize(argv)
|
|
13
|
+
if respond_to?(argv[0])
|
|
14
|
+
send(*argv)
|
|
15
|
+
else
|
|
16
|
+
parse_config
|
|
17
|
+
rb = BugsBunny::Rabbit.new
|
|
18
|
+
unless rb.respond_to?(argv[0])
|
|
19
|
+
puts "Can`t do that."; exit
|
|
20
|
+
end
|
|
21
|
+
log "Connecting to rabbitmq #{Opt[:rabbit][:vhost]}"
|
|
22
|
+
AMQP.start(Opt[:rabbit]) do
|
|
23
|
+
rb.start!(argv)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Write down a yml in ./ or config/ for ease use with
|
|
29
|
+
# bugs and on the
|
|
30
|
+
def config
|
|
31
|
+
path = "./"
|
|
32
|
+
path = "config/" if File.exists?("config/")
|
|
33
|
+
if config_exists?(path) && !Opt[:force]
|
|
34
|
+
puts "Config file already exists"
|
|
35
|
+
exit
|
|
36
|
+
else
|
|
37
|
+
File.copy(File.dirname(__FILE__) + "/#{CONFIG_FILE}", path)
|
|
38
|
+
puts "Copied config file to #{path}"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
def log(*args)
|
|
45
|
+
return unless Opt[:verbose]
|
|
46
|
+
puts *args
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def config_exists?(path, name = CONFIG_FILE)
|
|
50
|
+
File.exists?(path + name)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def parse_config
|
|
54
|
+
unless file = Opt[:config]
|
|
55
|
+
file = ["", "config/"].select { |p| config_exists?(p) }[0]
|
|
56
|
+
file += CONFIG_FILE
|
|
57
|
+
end
|
|
58
|
+
unless File.exists?(file)
|
|
59
|
+
puts "No config file"; exit
|
|
60
|
+
end
|
|
61
|
+
Opt[:rabbit].merge! YAML.load(File.read(file))
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Amqp rabbitmq stuff
|
|
2
|
+
module BugsBunny
|
|
3
|
+
|
|
4
|
+
class Rabbit
|
|
5
|
+
|
|
6
|
+
def initialize(params=nil)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def start!(command)
|
|
10
|
+
# @mq = MQ.new AMQP::connect
|
|
11
|
+
send(*command)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def vhosts
|
|
15
|
+
puts `rabbitmqctl list_vhosts`
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def queues(param=nil,name=nil)
|
|
19
|
+
if param == "new"
|
|
20
|
+
return halt("new <name>") unless name
|
|
21
|
+
BugsBunny::Record.create(name)
|
|
22
|
+
return halt
|
|
23
|
+
end
|
|
24
|
+
qs = BugsBunny::Record.all
|
|
25
|
+
unless param
|
|
26
|
+
print_table "Queues", qs.sort_by { |r| r.msgs }
|
|
27
|
+
else
|
|
28
|
+
qs.each(&:"#{param}")
|
|
29
|
+
end
|
|
30
|
+
halt
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def queue(q, action="info", *params)
|
|
34
|
+
rec = BugsBunny::Record.new(q)
|
|
35
|
+
if rec.respond_to?(action)
|
|
36
|
+
rec.send(action, *params)
|
|
37
|
+
else
|
|
38
|
+
puts "No such action for queues."
|
|
39
|
+
halt
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def exchanges
|
|
44
|
+
print_table "Queues", @mq.exchanges
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def print_table(title, arr)
|
|
48
|
+
return if arr.empty?
|
|
49
|
+
puts title
|
|
50
|
+
arr.each do |q|
|
|
51
|
+
puts q
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def halt(msg=nil)
|
|
56
|
+
BugsBunny::Rabbit.halt(msg)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def self.halt(msg=nil)
|
|
60
|
+
puts msg if msg
|
|
61
|
+
MQ.queues{ |q| q.unsubscribe }
|
|
62
|
+
AMQP.stop { EM.stop }
|
|
63
|
+
#EM.stop_event_loop
|
|
64
|
+
#exit
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
trap("INT") { halt }
|
|
68
|
+
trap("TERM") { halt }
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
end
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
module BugsBunny
|
|
2
|
+
class Record
|
|
3
|
+
attr_reader :name, :msgs, :users
|
|
4
|
+
@records = []
|
|
5
|
+
|
|
6
|
+
def self.all
|
|
7
|
+
# possible with amqp?
|
|
8
|
+
`rabbitmqctl list_queues -p #{Opt[:rabbit][:vhost]} name durable auto_delete arguments node messages_ready messages_unacknowledged messages_uncommitted messages consumers transactions memory`.split("\n").each do |l|
|
|
9
|
+
next if l =~ /Listing|\.\./
|
|
10
|
+
@records << BugsBunny::Record.new(*l.split("\t"))
|
|
11
|
+
end
|
|
12
|
+
@records
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.create(name)
|
|
16
|
+
MQ.queue(name).status do |msg, users|
|
|
17
|
+
puts "#{msg} messages, #{users} consumers."
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def initialize(*params)
|
|
22
|
+
@name, d, a,_,_,@msgs,_,_,@users, @transactions, @mem = *params
|
|
23
|
+
@durable = eval(d) if d #ugly
|
|
24
|
+
@auto_delete = eval(a) if a #more ugly
|
|
25
|
+
@mq = MQ.queue(@name, :passive => true)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def info
|
|
29
|
+
puts "About #{@name}"
|
|
30
|
+
@mq.status do |msg, users|
|
|
31
|
+
puts "#{msg} messages, #{users} consumers."
|
|
32
|
+
end
|
|
33
|
+
halt
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def list
|
|
37
|
+
inspect
|
|
38
|
+
EM.add_timer(1) { halt }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def inspect
|
|
42
|
+
puts ""
|
|
43
|
+
@mq.subscribe(:ack => true) do |h, body| #, :nowait => false
|
|
44
|
+
puts "-------\n"
|
|
45
|
+
print "QUEUE #{h.delivery_tag} (#{h.content_type}): "
|
|
46
|
+
print "Redelivered " if h.redelivered
|
|
47
|
+
puts "Mode #{h.delivery_mode}"
|
|
48
|
+
puts "Consumer: #{h.consumer_tag} Exchange: #{h.exchange}"
|
|
49
|
+
txt = read(body)
|
|
50
|
+
puts "\nBody:"
|
|
51
|
+
puts txt
|
|
52
|
+
puts
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
alias :live :inspect
|
|
56
|
+
|
|
57
|
+
def add(txt)
|
|
58
|
+
@mq.publish(txt)
|
|
59
|
+
halt
|
|
60
|
+
end
|
|
61
|
+
alias :publish :add
|
|
62
|
+
|
|
63
|
+
def pop
|
|
64
|
+
@mq.pop do |h, b|
|
|
65
|
+
puts "Pop => #{h}\n Body => #{b}" if b
|
|
66
|
+
halt
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
alias :get :pop
|
|
70
|
+
|
|
71
|
+
def purge
|
|
72
|
+
print "Purging #{name}... "
|
|
73
|
+
@mq.purge
|
|
74
|
+
print "Done.\n"
|
|
75
|
+
halt
|
|
76
|
+
end
|
|
77
|
+
alias :clean :purge
|
|
78
|
+
|
|
79
|
+
def delete
|
|
80
|
+
@mq.delete #:if_empty, if_unused, :no_wait
|
|
81
|
+
halt
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def to_s
|
|
85
|
+
"#{@name} #{durable}: #{@msgs} messages"
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def <=>(other)
|
|
89
|
+
@name <=> other.name
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
private
|
|
93
|
+
|
|
94
|
+
def read(dump, mode=:marshal)
|
|
95
|
+
case mode
|
|
96
|
+
when :marshal then Marshal.load(dump)
|
|
97
|
+
when :json then JSON.load(dump)
|
|
98
|
+
else dump
|
|
99
|
+
end
|
|
100
|
+
rescue
|
|
101
|
+
dump
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def durable
|
|
105
|
+
@durable ? "Durable" : "Volatile"
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def halt
|
|
109
|
+
BugsBunny::Rabbit.halt
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
end
|
data/lib/bugs_bunny.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#
|
|
2
|
+
# O que que ha, velhinho?
|
|
3
|
+
#
|
|
4
|
+
begin
|
|
5
|
+
require "nanite"
|
|
6
|
+
rescue LoadError
|
|
7
|
+
require "amqp"
|
|
8
|
+
require "mq"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
module BugsBunny
|
|
12
|
+
Opt = {:verbose => false, :force => false, :rabbit => {}}
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
require "bugs_bunny/cli"
|
|
16
|
+
require "bugs_bunny/rabbit"
|
|
17
|
+
require "bugs_bunny/record"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper"
|
|
2
|
+
|
|
3
|
+
describe BugsBunny::CLI do
|
|
4
|
+
|
|
5
|
+
it "should call itself it has the method" do
|
|
6
|
+
File.should_receive(:exists?).with("config/").and_return(false)
|
|
7
|
+
File.should_receive(:exists?).with("./rabbitmq.yml").and_return(false)
|
|
8
|
+
File.should_receive(:copy).and_return(true)
|
|
9
|
+
BugsBunny::CLI.new(["config"])
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "should not overwrite config file" do
|
|
13
|
+
File.should_receive(:exists?).with("config/").and_return(false)
|
|
14
|
+
File.should_receive(:exists?).with("./rabbitmq.yml").and_return(true)
|
|
15
|
+
File.should_not_receive(:copy)
|
|
16
|
+
BugsBunny::CLI.new(["config"])
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper"
|
|
2
|
+
|
|
3
|
+
describe BugsBunny::Rabbit do
|
|
4
|
+
|
|
5
|
+
it "should find vhosts" do
|
|
6
|
+
@rb = BugsBunny::Rabbit.new
|
|
7
|
+
@rb.should_receive(:"`").with("rabbitmqctl list_vhosts").and_return("foo")
|
|
8
|
+
@rb.should_receive(:halt)
|
|
9
|
+
@rb.vhosts
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
end
|
data/spec/spec.opts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: bugs_bunny
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
prerelease: false
|
|
5
|
+
segments:
|
|
6
|
+
- 0
|
|
7
|
+
- 0
|
|
8
|
+
- 7
|
|
9
|
+
version: 0.0.7
|
|
10
|
+
platform: ruby
|
|
11
|
+
authors:
|
|
12
|
+
- Marcos Piccinini
|
|
13
|
+
autorequire:
|
|
14
|
+
bindir: bin
|
|
15
|
+
cert_chain: []
|
|
16
|
+
|
|
17
|
+
date: 2010-03-03 00:00:00 -03:00
|
|
18
|
+
default_executable: bbunny
|
|
19
|
+
dependencies:
|
|
20
|
+
- !ruby/object:Gem::Dependency
|
|
21
|
+
name: amqp
|
|
22
|
+
prerelease: false
|
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
24
|
+
requirements:
|
|
25
|
+
- - ">="
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
segments:
|
|
28
|
+
- 0
|
|
29
|
+
- 6
|
|
30
|
+
- 7
|
|
31
|
+
version: 0.6.7
|
|
32
|
+
type: :runtime
|
|
33
|
+
version_requirements: *id001
|
|
34
|
+
- !ruby/object:Gem::Dependency
|
|
35
|
+
name: rspec
|
|
36
|
+
prerelease: false
|
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
segments:
|
|
42
|
+
- 1
|
|
43
|
+
- 2
|
|
44
|
+
- 9
|
|
45
|
+
version: 1.2.9
|
|
46
|
+
type: :development
|
|
47
|
+
version_requirements: *id002
|
|
48
|
+
- !ruby/object:Gem::Dependency
|
|
49
|
+
name: cucumber
|
|
50
|
+
prerelease: false
|
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
|
52
|
+
requirements:
|
|
53
|
+
- - ">="
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
segments:
|
|
56
|
+
- 0
|
|
57
|
+
version: "0"
|
|
58
|
+
type: :development
|
|
59
|
+
version_requirements: *id003
|
|
60
|
+
description: Play/Manage RabbitMQ. Vhosts, queues.
|
|
61
|
+
email: x@nofxx.com
|
|
62
|
+
executables:
|
|
63
|
+
- bbunny
|
|
64
|
+
extensions: []
|
|
65
|
+
|
|
66
|
+
extra_rdoc_files:
|
|
67
|
+
- LICENSE
|
|
68
|
+
- README.rdoc
|
|
69
|
+
files:
|
|
70
|
+
- .document
|
|
71
|
+
- .gitignore
|
|
72
|
+
- LICENSE
|
|
73
|
+
- README.rdoc
|
|
74
|
+
- Rakefile
|
|
75
|
+
- VERSION
|
|
76
|
+
- bin/bbunny
|
|
77
|
+
- bugs_bunny.gemspec
|
|
78
|
+
- cucumber.yml
|
|
79
|
+
- features/bugs_bunny.feature
|
|
80
|
+
- features/queues.feature
|
|
81
|
+
- features/step_definitions/bugs_bunny_steps.rb
|
|
82
|
+
- features/step_definitions/queue_steps.rb
|
|
83
|
+
- features/support/env.rb
|
|
84
|
+
- lib/bugs_bunny.rb
|
|
85
|
+
- lib/bugs_bunny/cli.rb
|
|
86
|
+
- lib/bugs_bunny/rabbit.rb
|
|
87
|
+
- lib/bugs_bunny/rabbitmq.yml
|
|
88
|
+
- lib/bugs_bunny/record.rb
|
|
89
|
+
- spec/bugs_bunny/cli_spec.rb
|
|
90
|
+
- spec/bugs_bunny/rabbit_spec.rb
|
|
91
|
+
- spec/bugs_bunny_spec.rb
|
|
92
|
+
- spec/spec.opts
|
|
93
|
+
- spec/spec_helper.rb
|
|
94
|
+
has_rdoc: true
|
|
95
|
+
homepage: http://github.com/nofxx/bugs_bunny
|
|
96
|
+
licenses: []
|
|
97
|
+
|
|
98
|
+
post_install_message:
|
|
99
|
+
rdoc_options:
|
|
100
|
+
- --charset=UTF-8
|
|
101
|
+
require_paths:
|
|
102
|
+
- lib
|
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
|
+
requirements:
|
|
105
|
+
- - ">="
|
|
106
|
+
- !ruby/object:Gem::Version
|
|
107
|
+
segments:
|
|
108
|
+
- 0
|
|
109
|
+
version: "0"
|
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
|
+
requirements:
|
|
112
|
+
- - ">="
|
|
113
|
+
- !ruby/object:Gem::Version
|
|
114
|
+
segments:
|
|
115
|
+
- 0
|
|
116
|
+
version: "0"
|
|
117
|
+
requirements: []
|
|
118
|
+
|
|
119
|
+
rubyforge_project:
|
|
120
|
+
rubygems_version: 1.3.6
|
|
121
|
+
signing_key:
|
|
122
|
+
specification_version: 3
|
|
123
|
+
summary: Play/Manage RabbitMQ
|
|
124
|
+
test_files:
|
|
125
|
+
- spec/bugs_bunny/cli_spec.rb
|
|
126
|
+
- spec/bugs_bunny/rabbit_spec.rb
|
|
127
|
+
- spec/bugs_bunny_spec.rb
|
|
128
|
+
- spec/spec_helper.rb
|