hare 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in hare.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Brian L. Troutwine
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.md ADDED
@@ -0,0 +1,39 @@
1
+ hare -- A command-line tool in Ruby to interact with message queues
2
+ ===================================================================
3
+
4
+ Introduction
5
+ ------------
6
+
7
+ Life with an AMQP message bus is dandy. `hare` exists to augment that
8
+ experience, allowing cron scripts and other system utilies to fire and
9
+ forget messages over the message bus or to receive messages to
10
+ stdout. `hare` is to RabbitMQ as `mailx` is to postfix.
11
+
12
+ Installation
13
+ ------------
14
+
15
+ Assuming you have a Ruby environment available, it's as simple as:
16
+
17
+ gem install hare
18
+
19
+ If not, consider the use of
20
+ [rbenv](https://github.com/sstephenson/rbenv) or
21
+ [rvm](http://beginrescueend.com/).
22
+
23
+ Example Usage
24
+ -------------
25
+
26
+ We'll send a message over the localhost message bus, exchange 'events', vhost '/' with route-key 'dev.event'. First, get a `hare` into listener mode:
27
+
28
+ $ hare --exchange_name events --route_key dev.event
29
+
30
+ and we'll send a message:
31
+
32
+ $ hare --exchange_name events --route_key dev.event --producer "that wasn't so bad"
33
+
34
+ Miscellania
35
+ -----------
36
+
37
+ `hare` has been developed as a part of my work with
38
+ [CarePilot](https://www.carepilot.com) and is released under the MIT
39
+ license. `hare` uses [semantic versioning](http://semver.org/).
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/hare ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # Hare command line interface script.
3
+ # Run <tt>hare -h</tt> to get more usage.
4
+
5
+ require 'hare'
6
+ Hare::Runner.new(ARGV).run!
data/hare.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "hare/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "hare"
7
+ s.version = Hare::VERSION
8
+ s.authors = ["Brian L. Troutwine"]
9
+ s.email = ["brian@troutwine.us"]
10
+ s.homepage = "https://github.com/blt/hare"
11
+ s.summary = %q{A small command-line tool for publishing to and consuming from AMQP queues.}
12
+ s.description = %q{The one pain-point I have had with AMQP is the lack of a series of command line tools for smoke-testing components or sending my own messages through a queue. Hare can be toggled either to produce messages, or to sit and listen/report for them.}
13
+
14
+ s.rubyforge_project = "hare"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_runtime_dependency "bunny", "~> 0.7.8"
23
+ end
@@ -0,0 +1,121 @@
1
+ require 'optparse'
2
+ require 'bunny'
3
+
4
+ module Hare
5
+ trap(:INT) { puts; exit }
6
+
7
+ class Runner
8
+ attr_accessor :options
9
+ attr_accessor :arguments
10
+
11
+ def initialize(argv)
12
+ @argv = argv
13
+
14
+ @options = {
15
+ :logging => false,
16
+ :publish => false,
17
+ :amqp => {
18
+ :host => 'localhost',
19
+ :port => '5672',
20
+ :exchange => {
21
+ :name => nil,
22
+ :kind => :direct,
23
+ },
24
+ :queue => '',
25
+ :vhost => '/',
26
+ :timeout => 0
27
+ }
28
+ }
29
+
30
+ parse!
31
+ end
32
+
33
+ def parser
34
+ @parser ||= OptionParser.new do |opts|
35
+ opts.banner = "Usage: hare [options] [MSG]"
36
+
37
+ opts.separator ""
38
+ opts.separator "Common Options:"
39
+ opts.on("-h", "--host HOST", "The AMQP server host") {
40
+ |host| @options[:amqp][:host] = host
41
+ }
42
+ opts.on("-p", "--port PORT", "The AMQP server host port") {
43
+ |port| @options[:amqp][:port] = port
44
+ }
45
+ opts.on("--vhost VHOST", "The AMQP vhost on which to connect") {
46
+ |vhost| @options[:amqp][:vhost] = vhost
47
+ }
48
+ opts.on("--exchange_name EXCHANGE", "The name of the AMQP exchange on which to connect") {
49
+ |exc| @options[:amqp][:exchange][:name] = exc
50
+ }
51
+ opts.on("--exchange_type TYPE", "The type of the AMQP exchange on which to connect") {
52
+ |exc| @options[:amqp][:exchange][:type] = exc
53
+ }
54
+ opts.on("--username NAME", "The AMQP username.") {
55
+ |u| @options[:amqp][:username] = u
56
+ }
57
+ opts.on("--password PSWD", "The AMQP password for the user given.") {
58
+ |p| @options[:amqp][:password] = p
59
+ }
60
+ opts.on("--route_key KEY", "The key to route messages over.") {
61
+ |k| @options[:amqp][:key] = k
62
+ }
63
+ opts.on("--logging", "Enable logging of AMQP interactions.") {
64
+ @options[:logging] = true
65
+ }
66
+
67
+ opts.separator ""
68
+ opts.separator "Consumer Options: "
69
+ opts.on("--queue QUEUE", "The queue on which to listen.") {
70
+ |q| @options[:amqp][:queue] = q
71
+ }
72
+ opts.on("--timeout TIME", "The time after which queue subscription will end.") {
73
+ |t| @options[:amqp][:timeout] = t
74
+ }
75
+
76
+ opts.separator ""
77
+ opts.separator "Producer Options: "
78
+ opts.on("--producer", "Toggle to enable producing messages") {
79
+ @options[:publish] = true
80
+ }
81
+
82
+ opts.separator ""
83
+ opts.on_tail("--help", "Show this message.") do
84
+ puts opts
85
+ exit
86
+ end
87
+ opts.on_tail("-v", "--version", "Show version") {
88
+ puts Hare::VERSION; exit
89
+ }
90
+ end
91
+ end
92
+
93
+ def parse!
94
+ parser.parse! @argv
95
+ @arguments = @argv
96
+ end
97
+
98
+ def run!
99
+ amqp = @options[:amqp]
100
+
101
+ b = Bunny.new(:host => amqp[:host], :port => amqp[:port], :logging => amqp[:logging])
102
+ b.start
103
+
104
+ eopts = amqp[:exchange]
105
+ exch = b.exchange(:name => eopts[:name], :type => eopts[:type])
106
+
107
+ if @options[:publish]
108
+ exch.publish(@arguments[0], :key => amqp[:key])
109
+ else
110
+ q = b.queue(amqp[:queue])
111
+ q.bind(exch, :key => amqp[:key])
112
+ q.subscribe(:timeout => amqp[:timeout]) do |msg|
113
+ puts "#{msg[:payload]}"
114
+ end
115
+ end
116
+
117
+ b.stop
118
+ end
119
+
120
+ end
121
+ end
@@ -0,0 +1,3 @@
1
+ module Hare
2
+ VERSION = "1.0.1"
3
+ end
data/lib/hare.rb ADDED
@@ -0,0 +1,7 @@
1
+ module Hare
2
+ ROOT = File.expand_path(File.dirname(__FILE__))
3
+
4
+ autoload :Runner, "#{ROOT}/hare/runner"
5
+ end
6
+
7
+ require "#{Hare::ROOT}/hare/version"
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hare
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brian L. Troutwine
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-11 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bunny
16
+ requirement: &69633210 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.7.8
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *69633210
25
+ description: The one pain-point I have had with AMQP is the lack of a series of command
26
+ line tools for smoke-testing components or sending my own messages through a queue.
27
+ Hare can be toggled either to produce messages, or to sit and listen/report for
28
+ them.
29
+ email:
30
+ - brian@troutwine.us
31
+ executables:
32
+ - hare
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - .gitignore
37
+ - Gemfile
38
+ - LICENSE
39
+ - README.md
40
+ - Rakefile
41
+ - bin/hare
42
+ - hare.gemspec
43
+ - lib/hare.rb
44
+ - lib/hare/runner.rb
45
+ - lib/hare/version.rb
46
+ homepage: https://github.com/blt/hare
47
+ licenses: []
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project: hare
66
+ rubygems_version: 1.8.10
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: A small command-line tool for publishing to and consuming from AMQP queues.
70
+ test_files: []