hare 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -25,11 +25,11 @@ Example Usage
25
25
 
26
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
27
 
28
- $ hare --exchange_name events --route_key dev.event
28
+ $ hare --exchange_name events --exchange_type topic --route_key dev.event
29
29
 
30
30
  and we'll send a message:
31
31
 
32
- $ hare --exchange_name events --route_key dev.event --producer "that wasn't so bad"
32
+ $ hare --exchange_name events --exchange_type topic --route_key dev.event --producer "that wasn't so bad"
33
33
 
34
34
  Miscellania
35
35
  -----------
data/hare.gemspec CHANGED
@@ -19,5 +19,5 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  # specify any dependencies here; for example:
22
- s.add_runtime_dependency "bunny", "~> 0.7.8"
22
+ s.add_runtime_dependency "amqp", '>= 0.9.2'
23
23
  end
data/lib/hare/runner.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'optparse'
2
- require 'bunny'
2
+ require 'amqp'
3
+ require 'eventmachine'
3
4
 
4
5
  module Hare
5
6
  trap(:INT) { puts; exit }
@@ -16,14 +17,17 @@ module Hare
16
17
  :publish => false,
17
18
  :amqp => {
18
19
  :host => 'localhost',
19
- :port => '5672',
20
+ :port => nil,
20
21
  :exchange => {
21
22
  :name => nil,
22
- :kind => :direct,
23
+ :kind => :topic,
23
24
  },
24
25
  :queue => '',
25
26
  :vhost => '/',
26
- :timeout => 0
27
+ :via_ssl => false,
28
+ :ssl_cert => nil,
29
+ :ssl_key => nil,
30
+ :ssl_verify => false
27
31
  }
28
32
  }
29
33
 
@@ -50,7 +54,7 @@ module Hare
50
54
  }
51
55
  opts.on("--exchange_type TYPE", "The type of the AMQP exchange on which to connect") do |type|
52
56
  if ['topic', 'direct', 'fanout'].member? type
53
- @options[:amqp][:exchange][:type] = type.to_sym
57
+ @options[:amqp][:exchange][:kind] = type.to_sym
54
58
  else
55
59
  puts "Exchange type must be (topic|direct|fanout), not #{type}."
56
60
  exit 1
@@ -68,15 +72,18 @@ module Hare
68
72
  opts.on("--logging", "Enable logging of AMQP interactions.") {
69
73
  @options[:logging] = true
70
74
  }
75
+ opts.on("--ssl_cert CERT", "Path to SSL chain certificates") do |c|
76
+ @options[:amqp][:ssl_cert] = c
77
+ end
78
+ opts.on("--ssl_key PRIVKEY", "Path to SSL private key") do |k|
79
+ @options[:amqp][:ssl_key] = k
80
+ end
71
81
 
72
82
  opts.separator ""
73
83
  opts.separator "Consumer Options: "
74
84
  opts.on("--queue QUEUE", "The queue on which to listen.") {
75
85
  |q| @options[:amqp][:queue] = q
76
86
  }
77
- opts.on("--timeout TIME", "The time after which queue subscription will end.") {
78
- |t| @options[:amqp][:timeout] = t
79
- }
80
87
 
81
88
  opts.separator ""
82
89
  opts.separator "Producer Options: "
@@ -103,24 +110,42 @@ module Hare
103
110
  def run!
104
111
  amqp = @options[:amqp]
105
112
 
106
- b = Bunny.new(:host => amqp[:host], :port => amqp[:port], :logging => amqp[:logging])
107
- b.start
113
+ EventMachine.run do
114
+ AMQP.connect(:host => amqp[:host], :port => amqp[:port], :vhost => amqp[:vhost],
115
+ :username => amqp[:username], :password => amqp[:password], :ssl => {
116
+ :cert_chain_file => amqp[:ssl_cert],
117
+ :private_key_file => amqp[:ssl_key]
118
+ },
119
+ :on_tcp_connection_failure => Proc.new { |settings|
120
+ puts "TCP Connection failure; details:\n\n#{settings.inspect}\n\n"; exit 1
121
+ },
122
+ :on_possible_authentication_failure => Proc.new { |settings|
123
+ puts "Authentication failure, I'm afraid:\n\n#{settings.inspect}\n\n"; exit 1
124
+ }) do |connection|
125
+
126
+ channel = AMQP::Channel.new(connection)
127
+ case amqp[:exchange][:kind]
128
+ when :direct
129
+ exchange = channel.direct(amqp[:exchange][:name])
130
+ when :fanout
131
+ exchange = channel.fanout(amqp[:exchange][:name])
132
+ when :topic
133
+ exchange = channel.topic(amqp[:exchange][:name])
134
+ end
108
135
 
109
- eopts = amqp[:exchange]
110
- exch = b.exchange(eopts[:name], :type => eopts[:type])
136
+ if @options[:publish]
137
+ exchange.publish(@arguments[0], :routing_key => amqp[:key]) do
138
+ connection.disconnect { EM.stop }
139
+ end
140
+ else
141
+ channel.queue(amqp[:queue]).bind(exchange, :key => amqp[:key]).subscribe do |payload|
142
+ puts payload
143
+ end
144
+ end
111
145
 
112
- if @options[:publish]
113
- exch.publish(@arguments[0].rstrip + "\n", :key => amqp[:key])
114
- else
115
- q = b.queue(amqp[:queue])
116
- q.bind(exch, :key => amqp[:key])
117
- q.subscribe(:timeout => amqp[:timeout]) do |msg|
118
- puts "#{msg[:payload]}"
119
146
  end
120
- end
121
-
122
- b.stop
123
- end
147
+ end # EM
148
+ end # run!
124
149
 
125
150
  end
126
151
  end
data/lib/hare/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hare
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hare
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,19 +9,19 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-24 00:00:00.000000000Z
12
+ date: 2012-02-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: bunny
16
- requirement: &74244340 !ruby/object:Gem::Requirement
15
+ name: amqp
16
+ requirement: &85280730 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ~>
19
+ - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.7.8
21
+ version: 0.9.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *74244340
24
+ version_requirements: *85280730
25
25
  description: The one pain-point I have had with AMQP is the lack of a series of command
26
26
  line tools for smoke-testing components or sending my own messages through a queue.
27
27
  Hare can be toggled either to produce messages, or to sit and listen/report for
@@ -68,3 +68,4 @@ signing_key:
68
68
  specification_version: 3
69
69
  summary: A small command-line tool for publishing to and consuming from AMQP queues.
70
70
  test_files: []
71
+ has_rdoc: