celldee-bunny 0.3.1 → 0.4.0

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/README CHANGED
@@ -1,6 +1,9 @@
1
1
  = Bunny: A synchronous Ruby AMQP client
2
2
 
3
3
  *GitHub* *repo*: http://github.com/celldee/bunny
4
+ *Rubyforge*: http://rubyforge.org/projects/bunny-amqp
5
+ *Twitter*: http://twitter.com/bunny_amqp
6
+ *Google* *Group*: http://groups.google.com/group/bunny-amqp
4
7
 
5
8
  === DESCRIPTION:
6
9
 
data/Rakefile CHANGED
@@ -1,8 +1,3 @@
1
- task :codegen do
2
- sh 'ruby ext/codegen.rb > lib/bunny/protocol/spec.rb'
3
- sh 'ruby lib/bunny/protocol/spec.rb'
4
- end
5
-
6
1
  task :spec do
7
2
  require 'spec/rake/spectask'
8
3
  Spec::Rake::SpecTask.new do |t|
data/bunny.gemspec CHANGED
@@ -1,8 +1,8 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{bunny}
3
- s.version = "0.3.1"
3
+ s.version = "0.4.0"
4
4
  s.authors = ["Chris Duncan"]
5
- s.date = %q{2009-05-10}
5
+ s.date = %q{2009-05-15}
6
6
  s.description = %q{Another synchronous Ruby AMQP client}
7
7
  s.email = %q{celldee@gmail.com}
8
8
  s.rubyforge_project = %q{bunny-amqp}
@@ -12,26 +12,26 @@ Gem::Specification.new do |s|
12
12
  s.homepage = %q{http://github.com/celldee/bunny}
13
13
  s.summary = %q{A synchronous Ruby AMQP client that enables interaction with AMQP-compliant brokers/servers.}
14
14
  s.files = ["LICENSE",
15
- "README",
16
- "Rakefile",
17
- "bunny.gemspec",
18
- "examples/simple.rb",
19
- "examples/simple_ack.rb",
20
- "examples/simple_consumer.rb",
21
- "examples/simple_fanout.rb",
22
- "examples/simple_publisher.rb",
23
- "examples/simple_topic.rb",
24
- "ext/amqp-0.8.json",
25
- "ext/codegen.rb",
26
- "lib/bunny.rb",
27
- "lib/bunny/client.rb",
28
- "lib/bunny/exchange.rb",
29
- "lib/bunny/protocol/protocol.rb",
30
- "lib/bunny/protocol/spec.rb",
31
- "lib/bunny/queue.rb",
32
- "lib/bunny/transport/buffer.rb",
33
- "lib/bunny/transport/frame.rb",
34
- "spec/bunny_spec.rb",
35
- "spec/exchange_spec.rb",
36
- "spec/queue_spec.rb"]
15
+ "README",
16
+ "Rakefile",
17
+ "bunny.gemspec",
18
+ "examples/simple.rb",
19
+ "examples/simple_ack.rb",
20
+ "examples/simple_consumer.rb",
21
+ "examples/simple_fanout.rb",
22
+ "examples/simple_publisher.rb",
23
+ "examples/simple_topic.rb",
24
+ "lib/bunny.rb",
25
+ "lib/bunny/client.rb",
26
+ "lib/bunny/exchange.rb",
27
+ "lib/bunny/queue.rb",
28
+ "lib/qrack/client.rb",
29
+ "lib/qrack/protocol/protocol.rb",
30
+ "lib/qrack/protocol/spec.rb",
31
+ "lib/qrack/qrack.rb",
32
+ "lib/qrack/transport/buffer.rb",
33
+ "lib/qrack/transport/frame.rb",
34
+ "spec/bunny_spec.rb",
35
+ "spec/exchange_spec.rb",
36
+ "spec/queue_spec.rb"]
37
37
  end
data/lib/bunny/client.rb CHANGED
@@ -8,7 +8,7 @@ The Client class provides the major Bunny API methods.
8
8
 
9
9
  =end
10
10
 
11
- class Client
11
+ class Client < Qrack::Client
12
12
  CONNECT_TIMEOUT = 1.0
13
13
  RETRY_DELAY = 10.0
14
14
 
@@ -40,7 +40,7 @@ Sets up a Bunny::Client object ready for connection to a broker/server. _Client_
40
40
 
41
41
  def initialize(opts = {})
42
42
  @host = opts[:host] || 'localhost'
43
- @port = opts[:port] || Protocol::PORT
43
+ @port = opts[:port] || Qrack::Protocol::PORT
44
44
  @user = opts[:user] || 'guest'
45
45
  @pass = opts[:pass] || 'guest'
46
46
  @vhost = opts[:vhost] || '/'
@@ -145,7 +145,7 @@ Returns hash of queues declared by Bunny.
145
145
  def send_frame(*args)
146
146
  args.each do |data|
147
147
  data.ticket = ticket if ticket and data.respond_to?(:ticket=)
148
- data = data.to_frame(channel) unless data.is_a?(Transport::Frame)
148
+ data = data.to_frame(channel) unless data.is_a?(Qrack::Transport::Frame)
149
149
  data.channel = channel
150
150
 
151
151
  log :send, data
@@ -155,7 +155,7 @@ Returns hash of queues declared by Bunny.
155
155
  end
156
156
 
157
157
  def next_frame
158
- frame = Transport::Frame.parse(buffer)
158
+ frame = Qrack::Transport::Frame.parse(buffer)
159
159
  log :received, frame
160
160
  frame
161
161
  end
@@ -166,7 +166,7 @@ Returns hash of queues declared by Bunny.
166
166
 
167
167
  def next_payload
168
168
  frame = next_frame
169
- frame.payload
169
+ frame and frame.payload
170
170
  end
171
171
 
172
172
  =begin rdoc
@@ -184,15 +184,15 @@ _Bunny_::_ProtocolError_ is raised. If successful, _Client_._status_ is set to <
184
184
 
185
185
  def close
186
186
  send_frame(
187
- Protocol::Channel::Close.new(:reply_code => 200, :reply_text => 'bye', :method_id => 0, :class_id => 0)
187
+ Qrack::Protocol::Channel::Close.new(:reply_code => 200, :reply_text => 'bye', :method_id => 0, :class_id => 0)
188
188
  )
189
- raise Bunny::ProtocolError, "Error closing channel #{channel}" unless next_method.is_a?(Protocol::Channel::CloseOk)
189
+ raise Bunny::ProtocolError, "Error closing channel #{channel}" unless next_method.is_a?(Qrack::Protocol::Channel::CloseOk)
190
190
 
191
191
  self.channel = 0
192
192
  send_frame(
193
- Protocol::Connection::Close.new(:reply_code => 200, :reply_text => 'Goodbye', :class_id => 0, :method_id => 0)
193
+ Qrack::Protocol::Connection::Close.new(:reply_code => 200, :reply_text => 'Goodbye', :class_id => 0, :method_id => 0)
194
194
  )
195
- raise Bunny::ProtocolError, "Error closing connection" unless next_method.is_a?(Protocol::Connection::CloseOk)
195
+ raise Bunny::ProtocolError, "Error closing connection" unless next_method.is_a?(Qrack::Protocol::Connection::CloseOk)
196
196
 
197
197
  close_socket
198
198
  end
@@ -222,12 +222,12 @@ _Bunny_::_ProtocolError_ is raised. If successful, _Client_._status_ is set to <
222
222
 
223
223
  def start_session
224
224
  @channel = 0
225
- write(Protocol::HEADER)
226
- write([1, 1, Protocol::VERSION_MAJOR, Protocol::VERSION_MINOR].pack('C4'))
227
- raise Bunny::ProtocolError, 'Connection initiation failed' unless next_method.is_a?(Protocol::Connection::Start)
225
+ write(Qrack::Protocol::HEADER)
226
+ write([1, 1, Qrack::Protocol::VERSION_MAJOR, Qrack::Protocol::VERSION_MINOR].pack('C4'))
227
+ raise Bunny::ProtocolError, 'Connection initiation failed' unless next_method.is_a?(Qrack::Protocol::Connection::Start)
228
228
 
229
229
  send_frame(
230
- Protocol::Connection::StartOk.new(
230
+ Qrack::Protocol::Connection::StartOk.new(
231
231
  {:platform => 'Ruby', :product => 'Bunny', :information => 'http://github.com/celldee/bunny', :version => VERSION},
232
232
  'AMQPLAIN',
233
233
  {:LOGIN => @user, :PASSWORD => @pass},
@@ -238,26 +238,26 @@ _Bunny_::_ProtocolError_ is raised. If successful, _Client_._status_ is set to <
238
238
  method = next_method
239
239
  raise Bunny::ProtocolError, "Connection failed - user: #{@user}, pass: #{@pass}" if method.nil?
240
240
 
241
- if method.is_a?(Protocol::Connection::Tune)
241
+ if method.is_a?(Qrack::Protocol::Connection::Tune)
242
242
  send_frame(
243
- Protocol::Connection::TuneOk.new( :channel_max => 0, :frame_max => 131072, :heartbeat => 0)
243
+ Qrack::Protocol::Connection::TuneOk.new( :channel_max => 0, :frame_max => 131072, :heartbeat => 0)
244
244
  )
245
245
  end
246
246
 
247
247
  send_frame(
248
- Protocol::Connection::Open.new(:virtual_host => @vhost, :capabilities => '', :insist => @insist)
248
+ Qrack::Protocol::Connection::Open.new(:virtual_host => @vhost, :capabilities => '', :insist => @insist)
249
249
  )
250
- raise Bunny::ProtocolError, 'Cannot open connection' unless next_method.is_a?(Protocol::Connection::OpenOk)
250
+ raise Bunny::ProtocolError, 'Cannot open connection' unless next_method.is_a?(Qrack::Protocol::Connection::OpenOk)
251
251
 
252
252
  @channel = 1
253
- send_frame(Protocol::Channel::Open.new)
254
- raise Bunny::ProtocolError, "Cannot open channel #{channel}" unless next_method.is_a?(Protocol::Channel::OpenOk)
253
+ send_frame(Qrack::Protocol::Channel::Open.new)
254
+ raise Bunny::ProtocolError, "Cannot open channel #{channel}" unless next_method.is_a?(Qrack::Protocol::Channel::OpenOk)
255
255
 
256
256
  send_frame(
257
- Protocol::Access::Request.new(:realm => '/data', :read => true, :write => true, :active => true, :passive => true)
257
+ Qrack::Protocol::Access::Request.new(:realm => '/data', :read => true, :write => true, :active => true, :passive => true)
258
258
  )
259
259
  method = next_method
260
- raise Bunny::ProtocolError, 'Access denied' unless method.is_a?(Protocol::Access::RequestOk)
260
+ raise Bunny::ProtocolError, 'Access denied' unless method.is_a?(Qrack::Protocol::Access::RequestOk)
261
261
  self.ticket = method.ticket
262
262
 
263
263
  # return status
@@ -269,7 +269,7 @@ _Bunny_::_ProtocolError_ is raised. If successful, _Client_._status_ is set to <
269
269
  private
270
270
 
271
271
  def buffer
272
- @buffer ||= Transport::Buffer.new(self)
272
+ @buffer ||= Qrack::Transport::Buffer.new(self)
273
273
  end
274
274
 
275
275
  def send_command(cmd, *args)
@@ -58,14 +58,14 @@ specification that applies to your target broker/server.
58
58
 
59
59
  unless name == "amq.#{type}" or name == ''
60
60
  client.send_frame(
61
- Protocol::Exchange::Declare.new(
61
+ Qrack::Protocol::Exchange::Declare.new(
62
62
  { :exchange => name, :type => type, :nowait => false }.merge(opts)
63
63
  )
64
64
  )
65
65
 
66
66
  raise Bunny::ProtocolError,
67
67
  "Error declaring exchange #{name}: type = #{type}" unless
68
- client.next_method.is_a?(Protocol::Exchange::DeclareOk)
68
+ client.next_method.is_a?(Qrack::Protocol::Exchange::DeclareOk)
69
69
  end
70
70
  end
71
71
 
@@ -98,19 +98,19 @@ nil
98
98
  def publish(data, opts = {})
99
99
  out = []
100
100
 
101
- out << Protocol::Basic::Publish.new(
101
+ out << Qrack::Protocol::Basic::Publish.new(
102
102
  { :exchange => name, :routing_key => opts.delete(:key) || key }.merge(opts)
103
103
  )
104
104
  data = data.to_s
105
- out << Protocol::Header.new(
106
- Protocol::Basic,
105
+ out << Qrack::Protocol::Header.new(
106
+ Qrack::Protocol::Basic,
107
107
  data.length, {
108
108
  :content_type => 'application/octet-stream',
109
109
  :delivery_mode => (opts.delete(:persistent) ? 2 : 1),
110
110
  :priority => 0
111
111
  }.merge(opts)
112
112
  )
113
- out << Transport::Frame::Body.new(data)
113
+ out << Qrack::Transport::Frame::Body.new(data)
114
114
 
115
115
  client.send_frame(*out)
116
116
  end
@@ -140,12 +140,12 @@ if successful. If an error occurs raises _Bunny_::_ProtocolError_.
140
140
  opts.delete(:nowait)
141
141
 
142
142
  client.send_frame(
143
- Protocol::Exchange::Delete.new({ :exchange => name, :nowait => false }.merge(opts))
143
+ Qrack::Protocol::Exchange::Delete.new({ :exchange => name, :nowait => false }.merge(opts))
144
144
  )
145
145
 
146
146
  raise Bunny::ProtocolError,
147
147
  "Error deleting exchange #{name}" unless
148
- client.next_method.is_a?(Protocol::Exchange::DeleteOk)
148
+ client.next_method.is_a?(Qrack::Protocol::Exchange::DeleteOk)
149
149
 
150
150
  client.exchanges.delete(name)
151
151
 
data/lib/bunny/queue.rb CHANGED
@@ -27,10 +27,10 @@ Queues must be attached to at least one exchange in order to receive messages fr
27
27
  opts.delete(:nowait)
28
28
 
29
29
  client.send_frame(
30
- Protocol::Queue::Declare.new({ :queue => name, :nowait => false }.merge(opts))
30
+ Qrack::Protocol::Queue::Declare.new({ :queue => name, :nowait => false }.merge(opts))
31
31
  )
32
32
 
33
- raise Bunny::ProtocolError, "Error declaring queue #{name}" unless client.next_method.is_a?(Protocol::Queue::DeclareOk)
33
+ raise Bunny::ProtocolError, "Error declaring queue #{name}" unless client.next_method.is_a?(Qrack::Protocol::Queue::DeclareOk)
34
34
  end
35
35
 
36
36
  =begin rdoc
@@ -52,7 +52,7 @@ ask to confirm a single message or a set of messages up to and including a speci
52
52
 
53
53
  def ack
54
54
  client.send_frame(
55
- Protocol::Basic::Ack.new(:delivery_tag => delivery_tag)
55
+ Qrack::Protocol::Basic::Ack.new(:delivery_tag => delivery_tag)
56
56
  )
57
57
 
58
58
  # reset delivery tag
@@ -91,7 +91,7 @@ a hash <tt>{:delivery_tag, :redelivered, :exchange, :routing_key, :message_count
91
91
  ack = opts.delete(:ack)
92
92
 
93
93
  client.send_frame(
94
- Protocol::Basic::Get.new({ :queue => name,
94
+ Qrack::Protocol::Basic::Get.new({ :queue => name,
95
95
  :consumer_tag => name,
96
96
  :no_ack => !ack,
97
97
  :nowait => true }.merge(opts))
@@ -99,9 +99,9 @@ a hash <tt>{:delivery_tag, :redelivered, :exchange, :routing_key, :message_count
99
99
 
100
100
  method = client.next_method
101
101
 
102
- if method.is_a?(Protocol::Basic::GetEmpty) then
102
+ if method.is_a?(Qrack::Protocol::Basic::GetEmpty) then
103
103
  return :queue_empty
104
- elsif !method.is_a?(Protocol::Basic::GetOk)
104
+ elsif !method.is_a?(Qrack::Protocol::Basic::GetOk)
105
105
  raise Bunny::ProtocolError, "Error getting message from queue #{name}"
106
106
  end
107
107
 
@@ -169,7 +169,7 @@ Returns hash {:message_count, :consumer_count}.
169
169
 
170
170
  def status
171
171
  client.send_frame(
172
- Protocol::Queue::Declare.new({ :queue => name, :passive => true })
172
+ Qrack::Protocol::Queue::Declare.new({ :queue => name, :passive => true })
173
173
  )
174
174
  method = client.next_method
175
175
  {:message_count => method.message_count, :consumer_count => method.consumer_count}
@@ -220,7 +220,7 @@ If <tt>:header => false</tt> only message payload is returned.
220
220
  ack = opts.delete(:ack)
221
221
 
222
222
  client.send_frame(
223
- Protocol::Basic::Consume.new({ :queue => name,
223
+ Qrack::Protocol::Basic::Consume.new({ :queue => name,
224
224
  :consumer_tag => consumer_tag,
225
225
  :no_ack => !ack,
226
226
  :nowait => false }.merge(opts))
@@ -228,12 +228,12 @@ If <tt>:header => false</tt> only message payload is returned.
228
228
 
229
229
  raise Bunny::ProtocolError,
230
230
  "Error subscribing to queue #{name}" unless
231
- client.next_method.is_a?(Protocol::Basic::ConsumeOk)
231
+ client.next_method.is_a?(Qrack::Protocol::Basic::ConsumeOk)
232
232
 
233
233
  while true
234
234
  method = client.next_method
235
235
 
236
- break if method.is_a?(Protocol::Basic::CancelOk)
236
+ break if method.is_a?(Qrack::Protocol::Basic::CancelOk)
237
237
 
238
238
  # get delivery tag to use for acknowledge
239
239
  self.delivery_tag = method.delivery_tag if ack
@@ -269,7 +269,7 @@ the server will not send any more messages for that consumer.
269
269
  # response from the server causing an error
270
270
  opts.delete(:nowait)
271
271
 
272
- client.send_frame( Protocol::Basic::Cancel.new({ :consumer_tag => consumer_tag }.merge(opts)))
272
+ client.send_frame( Qrack::Protocol::Basic::Cancel.new({ :consumer_tag => consumer_tag }.merge(opts)))
273
273
 
274
274
  end
275
275
 
@@ -299,7 +299,7 @@ bound to the direct exchange '' by default. If error occurs, a _Bunny_::_Protoco
299
299
 
300
300
  bindings[exchange] = opts
301
301
  client.send_frame(
302
- Protocol::Queue::Bind.new({ :queue => name,
302
+ Qrack::Protocol::Queue::Bind.new({ :queue => name,
303
303
  :exchange => exchange,
304
304
  :routing_key => opts.delete(:key),
305
305
  :nowait => false }.merge(opts))
@@ -307,7 +307,7 @@ bound to the direct exchange '' by default. If error occurs, a _Bunny_::_Protoco
307
307
 
308
308
  raise Bunny::ProtocolError,
309
309
  "Error binding queue #{name}" unless
310
- client.next_method.is_a?(Protocol::Queue::BindOk)
310
+ client.next_method.is_a?(Qrack::Protocol::Queue::BindOk)
311
311
 
312
312
  # return message
313
313
  :bind_ok
@@ -340,7 +340,7 @@ Removes a queue binding from an exchange. If error occurs, a _Bunny_::_ProtocolE
340
340
  bindings.delete(exchange)
341
341
 
342
342
  client.send_frame(
343
- Protocol::Queue::Unbind.new({ :queue => name,
343
+ Qrack::Protocol::Queue::Unbind.new({ :queue => name,
344
344
  :exchange => exchange,
345
345
  :routing_key => opts.delete(:key),
346
346
  :nowait => false }.merge(opts)
@@ -349,7 +349,7 @@ Removes a queue binding from an exchange. If error occurs, a _Bunny_::_ProtocolE
349
349
 
350
350
  raise Bunny::ProtocolError,
351
351
  "Error unbinding queue #{name}" unless
352
- client.next_method.is_a?(Protocol::Queue::UnbindOk)
352
+ client.next_method.is_a?(Qrack::Protocol::Queue::UnbindOk)
353
353
 
354
354
  # return message
355
355
  :unbind_ok
@@ -384,12 +384,12 @@ from queues if successful. If an error occurs raises _Bunny_::_ProtocolError_.
384
384
  opts.delete(:nowait)
385
385
 
386
386
  client.send_frame(
387
- Protocol::Queue::Delete.new({ :queue => name, :nowait => false }.merge(opts))
387
+ Qrack::Protocol::Queue::Delete.new({ :queue => name, :nowait => false }.merge(opts))
388
388
  )
389
389
 
390
390
  raise Bunny::ProtocolError,
391
391
  "Error deleting queue #{name}" unless
392
- client.next_method.is_a?(Protocol::Queue::DeleteOk)
392
+ client.next_method.is_a?(Qrack::Protocol::Queue::DeleteOk)
393
393
 
394
394
  client.queues.delete(name)
395
395
 
data/lib/bunny.rb CHANGED
@@ -5,29 +5,22 @@ $:.unshift File.expand_path(File.dirname(__FILE__))
5
5
  require file
6
6
  end
7
7
 
8
+ require 'qrack/qrack'
9
+
8
10
  require 'bunny/client'
9
11
  require 'bunny/exchange'
10
12
  require 'bunny/queue'
11
13
 
12
- require 'bunny/protocol/spec'
13
- require 'bunny/protocol/protocol'
14
-
15
- require 'bunny/transport/buffer'
16
- require 'bunny/transport/frame'
17
-
18
14
  module Bunny
19
15
 
20
- include Protocol
21
- include Transport
16
+ include Qrack
22
17
 
23
18
  class ProtocolError < StandardError; end
24
19
  class ServerDownError < StandardError; end
25
- class BufferOverflowError < StandardError; end
26
- class InvalidTypeError < StandardError; end
27
20
  class ConnectionError < StandardError; end
28
21
  class MessageError < StandardError; end
29
22
 
30
- VERSION = '0.3.1'
23
+ VERSION = '0.4.0'
31
24
 
32
25
  # Returns the Bunny version number
33
26
 
@@ -0,0 +1,5 @@
1
+ module Qrack
2
+ # Client ancestor class
3
+ class Client
4
+ end
5
+ end
@@ -1,4 +1,4 @@
1
- module Bunny
1
+ module Qrack
2
2
  module Protocol
3
3
  #:stopdoc:
4
4
  class Class::Method