bunny 0.5.3 → 0.6.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.
Files changed (41) hide show
  1. data/{README → README.rdoc} +9 -2
  2. data/bunny.gemspec +12 -7
  3. data/examples/simple_08.rb +1 -1
  4. data/examples/simple_09.rb +1 -1
  5. data/examples/simple_ack_08.rb +1 -1
  6. data/examples/simple_ack_09.rb +1 -1
  7. data/examples/simple_consumer_08.rb +6 -14
  8. data/examples/simple_consumer_09.rb +6 -14
  9. data/examples/simple_fanout_08.rb +2 -2
  10. data/examples/simple_fanout_09.rb +2 -2
  11. data/examples/simple_headers_08.rb +1 -1
  12. data/examples/simple_headers_09.rb +1 -1
  13. data/examples/simple_topic_08.rb +4 -4
  14. data/examples/simple_topic_09.rb +4 -4
  15. data/lib/bunny.rb +23 -15
  16. data/lib/bunny/channel08.rb +8 -2
  17. data/lib/bunny/channel09.rb +8 -2
  18. data/lib/bunny/client08.rb +67 -24
  19. data/lib/bunny/client09.rb +88 -48
  20. data/lib/bunny/exchange08.rb +55 -43
  21. data/lib/bunny/exchange09.rb +67 -54
  22. data/lib/bunny/queue08.rb +79 -137
  23. data/lib/bunny/queue09.rb +79 -141
  24. data/lib/bunny/subscription08.rb +85 -0
  25. data/lib/bunny/subscription09.rb +85 -0
  26. data/lib/qrack/client.rb +29 -10
  27. data/lib/qrack/protocol/spec08.rb +1 -0
  28. data/lib/qrack/protocol/spec09.rb +1 -0
  29. data/lib/qrack/qrack08.rb +1 -0
  30. data/lib/qrack/qrack09.rb +1 -0
  31. data/lib/qrack/queue.rb +1 -1
  32. data/lib/qrack/subscription.rb +102 -0
  33. data/spec/spec_08/bunny_spec.rb +6 -0
  34. data/spec/spec_08/connection_spec.rb +12 -0
  35. data/spec/spec_08/exchange_spec.rb +19 -3
  36. data/spec/spec_08/queue_spec.rb +87 -13
  37. data/spec/spec_09/bunny_spec.rb +7 -1
  38. data/spec/spec_09/connection_spec.rb +12 -0
  39. data/spec/spec_09/exchange_spec.rb +19 -3
  40. data/spec/spec_09/queue_spec.rb +94 -21
  41. metadata +11 -6
@@ -1,9 +1,14 @@
1
1
  = Bunny: A synchronous Ruby AMQP client
2
2
 
3
3
  *GitHub* *repo*: http://github.com/celldee/bunny
4
+
4
5
  *Rubyforge*: http://rubyforge.org/projects/bunny-amqp
6
+
5
7
  *Twitter*: http://twitter.com/bunny_amqp
8
+
6
9
  *Google* *Group*: http://groups.google.com/group/bunny-amqp
10
+
11
+ *Blog*: http://bunnyamqp.wordpress.com
7
12
 
8
13
  === DESCRIPTION:
9
14
 
@@ -23,7 +28,9 @@ Bunny is known to work with RabbitMQ versions 1.5.4, 1.5.5, 1.6.0 and version 0-
23
28
 
24
29
  *Rubyforge*: <tt>gem install bunny</tt>
25
30
 
26
- *GitHub*: <tt>gem install celldee-bunny</tt>
31
+ *Gemcutter*: <tt>gem install bunny</tt>
32
+
33
+ *GitHub*: Current gem is not available.
27
34
 
28
35
  === QUICK START:
29
36
 
@@ -41,7 +48,7 @@ Bunny is known to work with RabbitMQ versions 1.5.4, 1.5.5, 1.6.0 and version 0-
41
48
  q.publish('Hello everybody!')
42
49
 
43
50
  # get message from the queue
44
- msg = q.pop
51
+ msg = q.pop[:payload]
45
52
 
46
53
  puts 'This is the message: ' + msg + "\n\n"
47
54
 
@@ -1,18 +1,18 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{bunny}
3
- s.version = "0.5.3"
3
+ s.version = "0.6.0"
4
4
  s.authors = ["Chris Duncan"]
5
- s.date = %q{2009-09-07}
5
+ s.date = %q{2009-10-05}
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}
9
9
  s.has_rdoc = true
10
- s.extra_rdoc_files = [ "README" ]
11
- s.rdoc_options = [ "--main", "README" ]
10
+ s.extra_rdoc_files = [ "README.rdoc" ]
11
+ s.rdoc_options = [ "--main", "README.rdoc" ]
12
12
  s.homepage = %q{http://github.com/celldee/bunny/tree/master}
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",
15
+ "README.rdoc",
16
16
  "Rakefile",
17
17
  "bunny.gemspec",
18
18
  "examples/simple_08.rb",
@@ -38,9 +38,12 @@ Gem::Specification.new do |s|
38
38
  "lib/bunny/exchange09.rb",
39
39
  "lib/bunny/queue08.rb",
40
40
  "lib/bunny/queue09.rb",
41
+ "lib/bunny/subscription08.rb",
42
+ "lib/bunny/subscription09.rb",
41
43
  "lib/qrack/client.rb",
42
44
  "lib/qrack/channel.rb",
43
45
  "lib/qrack/queue.rb",
46
+ "lib/qrack/subscription.rb",
44
47
  "lib/qrack/protocol/protocol08.rb",
45
48
  "lib/qrack/protocol/protocol09.rb",
46
49
  "lib/qrack/protocol/spec08.rb",
@@ -54,7 +57,9 @@ Gem::Specification.new do |s|
54
57
  "spec/spec_08/bunny_spec.rb",
55
58
  "spec/spec_08/exchange_spec.rb",
56
59
  "spec/spec_08/queue_spec.rb",
60
+ "spec/spec_08/connection_spec.rb",
57
61
  "spec/spec_09/bunny_spec.rb",
58
62
  "spec/spec_09/exchange_spec.rb",
59
- "spec/spec_09/queue_spec.rb"]
60
- end
63
+ "spec/spec_09/queue_spec.rb",
64
+ "spec/spec_09/connection_spec.rb"]
65
+ end
@@ -22,7 +22,7 @@ q = b.queue('test1')
22
22
  q.publish('Hello everybody!')
23
23
 
24
24
  # get message from the queue
25
- msg = q.pop
25
+ msg = q.pop[:payload]
26
26
 
27
27
  puts 'This is the message: ' + msg + "\n\n"
28
28
 
@@ -22,7 +22,7 @@ q = b.queue('test1')
22
22
  q.publish('Hello everybody!')
23
23
 
24
24
  # get message from the queue
25
- msg = q.pop
25
+ msg = q.pop[:payload]
26
26
 
27
27
  puts 'This is the message: ' + msg + "\n\n"
28
28
 
@@ -22,7 +22,7 @@ q = b.queue('test1')
22
22
  q.publish('Testing acknowledgements')
23
23
 
24
24
  # get message from the queue
25
- msg = q.pop(:ack => true)
25
+ msg = q.pop(:ack => true)[:payload]
26
26
 
27
27
  # acknowledge receipt of message
28
28
  q.ack
@@ -22,7 +22,7 @@ q = b.queue('test1')
22
22
  q.publish('Testing acknowledgements')
23
23
 
24
24
  # get message from the queue
25
- msg = q.pop(:ack => true)
25
+ msg = q.pop(:ack => true)[:payload]
26
26
 
27
27
  # acknowledge receipt of message
28
28
  q.ack
@@ -44,18 +44,10 @@ exch = b.exchange('sorting_room')
44
44
  # bind queue to exchange
45
45
  q.bind(exch, :key => 'fred')
46
46
 
47
- # initialize counter
48
- i = 1
49
-
50
47
  # subscribe to queue
51
- begin
52
- ret = q.subscribe(:consumer_tag => 'testtag1', :timeout => 30) do |msg|
53
- puts "#{i.to_s}: #{msg}"
54
- i+=1
55
- end
56
- rescue Qrack::ClientTimeout
57
- puts '==== simple_consumer_08.rb timed out - closing down ===='
58
- q.unsubscribe(:consumer_tag => 'testtag1')
59
- # close the connection
60
- b.stop
61
- end
48
+ q.subscribe(:consumer_tag => 'testtag1', :timeout => 30) do |msg|
49
+ puts "#{q.subscription.message_count}: #{msg[:payload]}"
50
+ end
51
+
52
+ # Close client
53
+ b.stop
@@ -44,18 +44,10 @@ exch = b.exchange('sorting_room')
44
44
  # bind queue to exchange
45
45
  q.bind(exch, :key => 'fred')
46
46
 
47
- # initialize counter
48
- i = 1
49
-
50
47
  # subscribe to queue
51
- begin
52
- ret = q.subscribe(:consumer_tag => 'testtag1', :timeout => 30) do |msg|
53
- puts "#{i.to_s}: #{msg}"
54
- i+=1
55
- end
56
- rescue Qrack::ClientTimeout
57
- puts '==== simple_consumer_09.rb timed out - closing down ===='
58
- q.unsubscribe(:consumer_tag => 'testtag1')
59
- # close the connection
60
- b.stop
61
- end
48
+ q.subscribe(:consumer_tag => 'testtag1', :timeout => 30) do |msg|
49
+ puts "#{q.subscription.message_count}: #{msg[:payload]}"
50
+ end
51
+
52
+ # Close client
53
+ b.stop
@@ -30,9 +30,9 @@ q2.bind(exch)
30
30
  exch.publish('This message will be fanned out')
31
31
 
32
32
  # get message from the queues
33
- msg = q1.pop
33
+ msg = q1.pop[:payload]
34
34
  puts 'This is the message from q1: ' + msg + "\n\n"
35
- msg = q2.pop
35
+ msg = q2.pop[:payload]
36
36
  puts 'This is the message from q2: ' + msg + "\n\n"
37
37
 
38
38
  # close the client connection
@@ -30,9 +30,9 @@ q2.bind(exch)
30
30
  exch.publish('This message will be fanned out')
31
31
 
32
32
  # get message from the queues
33
- msg = q1.pop
33
+ msg = q1.pop[:payload]
34
34
  puts 'This is the message from q1: ' + msg + "\n\n"
35
- msg = q2.pop
35
+ msg = q2.pop[:payload]
36
36
  puts 'This is the message from q2: ' + msg + "\n\n"
37
37
 
38
38
  # close the client connection
@@ -32,7 +32,7 @@ header_exch.publish('Headers test msg 2', :headers => {'h1'=>'z'})
32
32
  # get messages from the queue - should only be msg 1 that got through
33
33
  msg = ""
34
34
  until msg == :queue_empty do
35
- msg = q.pop
35
+ msg = q.pop[:payload]
36
36
  puts 'This is a message from the header_q1 queue: ' + msg + "\n" unless msg == :queue_empty
37
37
  end
38
38
 
@@ -32,7 +32,7 @@ header_exch.publish('Headers test msg 2', :headers => {'h1'=>'z'})
32
32
  # get messages from the queue - should only be msg 1 that got through
33
33
  msg = ""
34
34
  until msg == :queue_empty do
35
- msg = q.pop
35
+ msg = q.pop[:payload]
36
36
  puts 'This is a message from the header_q1 queue: ' + msg + "\n" unless msg == :queue_empty
37
37
  end
38
38
 
@@ -38,20 +38,20 @@ sports_results.publish('British Lions 15 : South Africa 12', :key => 'rugby.resu
38
38
  # get message from the queues
39
39
 
40
40
  # soccer queue got the soccer message
41
- msg = soccer.pop
41
+ msg = soccer.pop[:payload]
42
42
  puts 'This is a message from the soccer q: ' + msg + "\n\n"
43
43
 
44
44
  # cricket queue got the cricket message
45
- msg = cricket.pop
45
+ msg = cricket.pop[:payload]
46
46
  puts 'This is a message from the cricket q: ' + msg + "\n\n"
47
47
 
48
48
  # rugby queue got the rugby message
49
- msg = rugby.pop
49
+ msg = rugby.pop[:payload]
50
50
  puts 'This is a message from the rugby q: ' + msg + "\n\n"
51
51
 
52
52
  # allsport queue got all of the messages
53
53
  until msg == :queue_empty do
54
- msg = allsport.pop
54
+ msg = allsport.pop[:payload]
55
55
  puts 'This is a message from the allsport q: ' + msg + "\n\n" unless msg == :queue_empty
56
56
  end
57
57
 
@@ -38,20 +38,20 @@ sports_results.publish('British Lions 15 : South Africa 12', :key => 'rugby.resu
38
38
  # get message from the queues
39
39
 
40
40
  # soccer queue got the soccer message
41
- msg = soccer.pop
41
+ msg = soccer.pop[:payload]
42
42
  puts 'This is a message from the soccer q: ' + msg + "\n\n"
43
43
 
44
44
  # cricket queue got the cricket message
45
- msg = cricket.pop
45
+ msg = cricket.pop[:payload]
46
46
  puts 'This is a message from the cricket q: ' + msg + "\n\n"
47
47
 
48
48
  # rugby queue got the rugby message
49
- msg = rugby.pop
49
+ msg = rugby.pop[:payload]
50
50
  puts 'This is a message from the rugby q: ' + msg + "\n\n"
51
51
 
52
52
  # allsport queue got all of the messages
53
53
  until msg == :queue_empty do
54
- msg = allsport.pop
54
+ msg = allsport.pop[:payload]
55
55
  puts 'This is a message from the allsport q: ' + msg + "\n\n" unless msg == :queue_empty
56
56
  end
57
57
 
@@ -7,12 +7,16 @@ end
7
7
 
8
8
  module Bunny
9
9
 
10
- class ProtocolError < StandardError; end
11
- class ServerDownError < StandardError; end
12
10
  class ConnectionError < StandardError; end
11
+ class ForcedChannelCloseError < StandardError; end
12
+ class ForcedConnectionCloseError < StandardError; end
13
13
  class MessageError < StandardError; end
14
+ class ProtocolError < StandardError; end
15
+ class ServerDownError < StandardError; end
16
+ class UnsubscribeError < StandardError; end
17
+ class AcknowledgementError < StandardError; end
14
18
 
15
- VERSION = '0.5.3'
19
+ VERSION = '0.6.0'
16
20
 
17
21
  # Returns the Bunny version number
18
22
 
@@ -25,10 +29,9 @@ module Bunny
25
29
  def self.new(opts = {})
26
30
  # Set up Bunny according to AMQP spec version required
27
31
  spec_version = opts[:spec] || '08'
28
- setup(spec_version, opts)
29
-
32
+
30
33
  # Return client
31
- @client
34
+ setup(spec_version, opts)
32
35
  end
33
36
 
34
37
  # Runs a code block using a short-lived connection
@@ -38,13 +41,14 @@ module Bunny
38
41
 
39
42
  # Set up Bunny according to AMQP spec version required
40
43
  spec_version = opts[:spec] || '08'
41
- setup(spec_version, opts)
44
+ client = setup(spec_version, opts)
42
45
 
43
- @client.start
44
-
45
- block.call(@client)
46
-
47
- @client.stop
46
+ begin
47
+ client.start
48
+ block.call(client)
49
+ ensure
50
+ client.stop
51
+ end
48
52
 
49
53
  # Return success
50
54
  :run_ok
@@ -60,8 +64,9 @@ module Bunny
60
64
  require 'bunny/exchange08'
61
65
  require 'bunny/queue08'
62
66
  require 'bunny/channel08'
67
+ require 'bunny/subscription08'
63
68
 
64
- @client = Bunny::Client.new(opts)
69
+ client = Bunny::Client.new(opts)
65
70
  else
66
71
  # AMQP 0-9-1 specification
67
72
  require 'qrack/qrack09'
@@ -69,11 +74,14 @@ module Bunny
69
74
  require 'bunny/exchange09'
70
75
  require 'bunny/queue09'
71
76
  require 'bunny/channel09'
77
+ require 'bunny/subscription09'
72
78
 
73
- @client = Bunny::Client09.new(opts)
79
+ client = Bunny::Client09.new(opts)
74
80
  end
75
81
 
76
82
  include Qrack
83
+
84
+ client
77
85
  end
78
86
 
79
- end
87
+ end
@@ -8,7 +8,10 @@ module Bunny
8
8
  def open
9
9
  client.channel = self
10
10
  client.send_frame(Qrack::Protocol::Channel::Open.new)
11
- raise Bunny::ProtocolError, "Cannot open channel #{number}" unless client.next_method.is_a?(Qrack::Protocol::Channel::OpenOk)
11
+
12
+ method = client.next_method
13
+
14
+ client.check_response(method, Qrack::Protocol::Channel::OpenOk, "Cannot open channel #{number}")
12
15
 
13
16
  @active = true
14
17
  :open_ok
@@ -19,7 +22,10 @@ module Bunny
19
22
  client.send_frame(
20
23
  Qrack::Protocol::Channel::Close.new(:reply_code => 200, :reply_text => 'bye', :method_id => 0, :class_id => 0)
21
24
  )
22
- raise Bunny::ProtocolError, "Error closing channel #{number}" unless client.next_method.is_a?(Qrack::Protocol::Channel::CloseOk)
25
+
26
+ method = client.next_method
27
+
28
+ client.check_response(method, Qrack::Protocol::Channel::CloseOk, "Error closing channel #{number}")
23
29
 
24
30
  @active = false
25
31
  :close_ok
@@ -8,7 +8,10 @@ module Bunny
8
8
  def open
9
9
  client.channel = self
10
10
  client.send_frame(Qrack::Protocol09::Channel::Open.new)
11
- raise Bunny::ProtocolError, "Cannot open channel #{number}" unless client.next_method.is_a?(Qrack::Protocol09::Channel::OpenOk)
11
+
12
+ method = client.next_method
13
+
14
+ client.check_response(method, Qrack::Protocol09::Channel::OpenOk, "Cannot open channel #{number}")
12
15
 
13
16
  @active = true
14
17
  :open_ok
@@ -19,7 +22,10 @@ module Bunny
19
22
  client.send_frame(
20
23
  Qrack::Protocol09::Channel::Close.new(:reply_code => 200, :reply_text => 'bye', :method_id => 0, :class_id => 0)
21
24
  )
22
- raise Bunny::ProtocolError, "Error closing channel #{number}" unless client.next_method.is_a?(Qrack::Protocol09::Channel::CloseOk)
25
+
26
+ method = client.next_method
27
+
28
+ client.check_response(method, Qrack::Protocol09::Channel::CloseOk, "Error closing channel #{number}")
23
29
 
24
30
  @active = false
25
31
  :close_ok
@@ -22,10 +22,15 @@ Sets up a Bunny::Client object ready for connection to a broker/server. _Client_
22
22
  ==== OPTIONS:
23
23
 
24
24
  * <tt>:host => '_hostname_' (default = 'localhost')</tt>
25
- * <tt>:port => _portno_ (default = 5672)</tt>
25
+ * <tt>:port => _portno_ (default = 5672 or 5671 if :ssl set to true)</tt>
26
26
  * <tt>:vhost => '_vhostname_' (default = '/')</tt>
27
27
  * <tt>:user => '_username_' (default = 'guest')</tt>
28
28
  * <tt>:pass => '_password_' (default = 'guest')</tt>
29
+ * <tt>:ssl => true or false (default = false)</tt> - If set to _true_, ssl
30
+ encryption will be used and port will default to 5671.
31
+ * <tt>:verify_ssl => true or false (default = true)</tt> - If ssl is enabled,
32
+ this will cause OpenSSL to validate the server certificate unless this
33
+ parameter is set to _false_.
29
34
  * <tt>:logfile => '_logfilepath_' (default = nil)</tt>
30
35
  * <tt>:logging => true or false (_default_)</tt> - If set to _true_, session information is sent
31
36
  to STDOUT if <tt>:logfile</tt> has not been specified. Otherwise, session information is written to
@@ -37,16 +42,49 @@ Sets up a Bunny::Client object ready for connection to a broker/server. _Client_
37
42
  * <tt>:frame_max => maximum frame size in bytes (default = 131072)</tt>
38
43
  * <tt>:channel_max => maximum number of channels (default = 0 no maximum)</tt>
39
44
  * <tt>:heartbeat => number of seconds (default = 0 no heartbeat)</tt>
45
+ * <tt>:connect_timeout => number of seconds before Qrack::ConnectionTimeout is raised (default = 5)</tt>
40
46
 
41
47
  =end
42
48
 
43
49
  def initialize(opts = {})
44
50
  super
45
51
  @spec = '0-8'
46
- @port = opts[:port] || Qrack::Protocol::PORT
52
+ @port = opts[:port] || (opts[:ssl] ? Qrack::Protocol::SSL_PORT : Qrack::Protocol::PORT)
47
53
  @insist = opts[:insist]
48
54
  end
49
55
 
56
+ =begin rdoc
57
+
58
+ === DESCRIPTION:
59
+
60
+ Checks response from AMQP methods and takes appropriate action
61
+
62
+ =end
63
+
64
+ def check_response(received_method, expected_method, err_msg, err_class = Bunny::ProtocolError)
65
+ case
66
+ when received_method.is_a?(Qrack::Protocol::Connection::Close)
67
+ # Clean up the socket
68
+ close_socket
69
+
70
+ raise Bunny::ForcedConnectionCloseError,
71
+ "Error Reply Code: #{received_method.reply_code}\nError Reply Text: #{received_method.reply_text}"
72
+
73
+ when received_method.is_a?(Qrack::Protocol::Channel::Close)
74
+ # Clean up the channel
75
+ channel.active = false
76
+
77
+ raise Bunny::ForcedChannelCloseError,
78
+ "Error Reply Code: #{received_method.reply_code}\nError Reply Text: #{received_method.reply_text}"
79
+
80
+ when !received_method.is_a?(expected_method)
81
+ raise err_class, err_msg
82
+
83
+ else
84
+ :response_ok
85
+ end
86
+ end
87
+
50
88
  def close_connection
51
89
  # Set client channel to zero
52
90
  switch_channel(0)
@@ -54,7 +92,11 @@ Sets up a Bunny::Client object ready for connection to a broker/server. _Client_
54
92
  send_frame(
55
93
  Qrack::Protocol::Connection::Close.new(:reply_code => 200, :reply_text => 'Goodbye', :class_id => 0, :method_id => 0)
56
94
  )
57
- raise Bunny::ProtocolError, "Error closing connection" unless next_method.is_a?(Qrack::Protocol::Connection::CloseOk)
95
+
96
+ method = next_method
97
+
98
+ check_response(method, Qrack::Protocol::Connection::CloseOk, "Error closing connection")
99
+
58
100
  end
59
101
 
60
102
  def create_channel
@@ -92,8 +134,7 @@ Exchange
92
134
  =end
93
135
 
94
136
  def exchange(name, opts = {})
95
- return exchanges[name] if exchanges.has_key?(name)
96
- Bunny::Exchange.new(self, name, opts)
137
+ exchanges[name] || Bunny::Exchange.new(self, name, opts)
97
138
  end
98
139
 
99
140
  def init_connection
@@ -152,7 +193,7 @@ Exchange
152
193
  )
153
194
 
154
195
  frame = next_frame
155
- raise Bunny::ProtocolError, "Connection failed - user: #{@user}, pass: #{@pass}" if frame.nil?
196
+ raise Bunny::ProtocolError, "Connection failed - user: #{@user}" if frame.nil?
156
197
 
157
198
  method = frame.payload
158
199
 
@@ -168,7 +209,7 @@ Exchange
168
209
 
169
210
  case method = next_method
170
211
  when Qrack::Protocol::Connection::OpenOk
171
- return :ok
212
+ :ok
172
213
  when Qrack::Protocol::Connection::Redirect
173
214
  raise Bunny::ConnectionError, "Cannot connect to the specified server - host: #{@host}, port: #{@port}" if @insist
174
215
 
@@ -217,9 +258,9 @@ true, they are applied to the entire connection.
217
258
  Qrack::Protocol::Basic::Qos.new({ :prefetch_size => 0, :prefetch_count => 1, :global => false }.merge(opts))
218
259
  )
219
260
 
220
- raise Bunny::ProtocolError,
221
- "Error specifying Quality of Service" unless
222
- next_method.is_a?(Qrack::Protocol::Basic::QosOk)
261
+ method = next_method
262
+
263
+ check_response(method, Qrack::Protocol::Basic::QosOk, "Error specifying Quality of Service")
223
264
 
224
265
  # return confirmation
225
266
  :qos_ok
@@ -265,9 +306,8 @@ Queue
265
306
  name = nil
266
307
  end
267
308
 
268
- return queues[name] if queues.has_key?(name)
269
-
270
- Bunny::Queue.new(self, name, opts)
309
+ # Queue is responsible for placing itself in the list of queues
310
+ queues[name] || Bunny::Queue.new(self, name, opts)
271
311
  end
272
312
 
273
313
  =begin rdoc
@@ -297,8 +337,11 @@ the message, potentially then delivering it to an alternative subscriber.
297
337
  send_frame(
298
338
  Qrack::Protocol::Access::Request.new(:realm => '/data', :read => true, :write => true, :active => true, :passive => true)
299
339
  )
340
+
300
341
  method = next_method
301
- raise Bunny::ProtocolError, 'Access denied' unless method.is_a?(Qrack::Protocol::Access::RequestOk)
342
+
343
+ check_response(method, Qrack::Protocol::Access::RequestOk, "Access denied")
344
+
302
345
  self.ticket = method.ticket
303
346
  end
304
347
 
@@ -384,10 +427,10 @@ after a commit.
384
427
 
385
428
  def tx_commit
386
429
  send_frame(Qrack::Protocol::Tx::Commit.new())
387
-
388
- raise Bunny::ProtocolError,
389
- "Error commiting transaction" unless
390
- next_method.is_a?(Qrack::Protocol::Tx::CommitOk)
430
+
431
+ method = next_method
432
+
433
+ check_response(method, Qrack::Protocol::Tx::CommitOk, "Error commiting transaction")
391
434
 
392
435
  # return confirmation
393
436
  :commit_ok
@@ -409,9 +452,9 @@ after a rollback.
409
452
  def tx_rollback
410
453
  send_frame(Qrack::Protocol::Tx::Rollback.new())
411
454
 
412
- raise Bunny::ProtocolError,
413
- "Error rolling back transaction" unless
414
- next_method.is_a?(Qrack::Protocol::Tx::RollbackOk)
455
+ method = next_method
456
+
457
+ check_response(method, Qrack::Protocol::Tx::RollbackOk, "Error rolling back transaction")
415
458
 
416
459
  # return confirmation
417
460
  :rollback_ok
@@ -432,10 +475,10 @@ using the Commit or Rollback methods.
432
475
 
433
476
  def tx_select
434
477
  send_frame(Qrack::Protocol::Tx::Select.new())
478
+
479
+ method = next_method
435
480
 
436
- raise Bunny::ProtocolError,
437
- "Error initiating transactions for current channel" unless
438
- next_method.is_a?(Qrack::Protocol::Tx::SelectOk)
481
+ check_response(method, Qrack::Protocol::Tx::SelectOk, "Error initiating transactions for current channel")
439
482
 
440
483
  # return confirmation
441
484
  :select_ok