bunny 0.6.3.rc2 → 0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/.gitignore +8 -0
  2. data/.rspec +3 -0
  3. data/.travis.yml +15 -0
  4. data/.yardopts +9 -0
  5. data/CHANGELOG +3 -0
  6. data/Gemfile +39 -0
  7. data/Gemfile.lock +34 -0
  8. data/LICENSE +5 -4
  9. data/README.textile +54 -0
  10. data/Rakefile +15 -13
  11. data/bunny.gemspec +42 -61
  12. data/examples/simple_08.rb +4 -2
  13. data/examples/simple_09.rb +4 -2
  14. data/examples/simple_ack_08.rb +3 -1
  15. data/examples/simple_ack_09.rb +3 -1
  16. data/examples/simple_consumer_08.rb +4 -2
  17. data/examples/simple_consumer_09.rb +4 -2
  18. data/examples/simple_fanout_08.rb +3 -1
  19. data/examples/simple_fanout_09.rb +3 -1
  20. data/examples/simple_headers_08.rb +5 -3
  21. data/examples/simple_headers_09.rb +5 -3
  22. data/examples/simple_publisher_08.rb +3 -1
  23. data/examples/simple_publisher_09.rb +3 -1
  24. data/examples/simple_topic_08.rb +5 -3
  25. data/examples/simple_topic_09.rb +5 -3
  26. data/ext/amqp-0.8.json +616 -0
  27. data/ext/amqp-0.9.1.json +388 -0
  28. data/ext/config.yml +4 -0
  29. data/ext/qparser.rb +463 -0
  30. data/lib/bunny.rb +88 -66
  31. data/lib/bunny/channel08.rb +38 -38
  32. data/lib/bunny/channel09.rb +37 -37
  33. data/lib/bunny/client08.rb +184 -206
  34. data/lib/bunny/client09.rb +277 -363
  35. data/lib/bunny/consumer.rb +35 -0
  36. data/lib/bunny/exchange08.rb +37 -41
  37. data/lib/bunny/exchange09.rb +106 -124
  38. data/lib/bunny/queue08.rb +216 -202
  39. data/lib/bunny/queue09.rb +256 -326
  40. data/lib/bunny/subscription08.rb +30 -29
  41. data/lib/bunny/subscription09.rb +84 -83
  42. data/lib/bunny/version.rb +5 -0
  43. data/lib/qrack/amq-client-url.rb +165 -0
  44. data/lib/qrack/channel.rb +19 -17
  45. data/lib/qrack/client.rb +152 -151
  46. data/lib/qrack/errors.rb +5 -0
  47. data/lib/qrack/protocol/protocol08.rb +132 -130
  48. data/lib/qrack/protocol/protocol09.rb +133 -131
  49. data/lib/qrack/protocol/spec08.rb +2 -0
  50. data/lib/qrack/protocol/spec09.rb +2 -0
  51. data/lib/qrack/qrack08.rb +7 -10
  52. data/lib/qrack/qrack09.rb +7 -10
  53. data/lib/qrack/queue.rb +27 -40
  54. data/lib/qrack/subscription.rb +102 -101
  55. data/lib/qrack/transport/buffer08.rb +266 -264
  56. data/lib/qrack/transport/buffer09.rb +268 -264
  57. data/lib/qrack/transport/frame08.rb +13 -11
  58. data/lib/qrack/transport/frame09.rb +9 -7
  59. data/spec/spec_08/bunny_spec.rb +48 -45
  60. data/spec/spec_08/connection_spec.rb +10 -7
  61. data/spec/spec_08/exchange_spec.rb +145 -143
  62. data/spec/spec_08/queue_spec.rb +161 -161
  63. data/spec/spec_09/bunny_spec.rb +46 -44
  64. data/spec/spec_09/connection_spec.rb +15 -8
  65. data/spec/spec_09/exchange_spec.rb +147 -145
  66. data/spec/spec_09/queue_spec.rb +182 -184
  67. metadata +60 -41
  68. data/README.rdoc +0 -66
@@ -1,48 +1,59 @@
1
- $:.unshift File.expand_path(File.dirname(__FILE__))
1
+ # encoding: utf-8
2
2
 
3
- # Ruby standard libraries
4
- %w[socket thread timeout logger].each do |file|
5
- require file
6
- end
3
+ require "socket"
4
+ require "thread"
5
+ require "timeout"
6
+ require "logger"
7
7
 
8
- require "bunny/version"
8
+ require File.expand_path("../bunny/version", __FILE__)
9
+ # if we don't require the version file the same way as in the gemspec,
10
+ # the version file will be loaded twice. and we hate warnings.
9
11
 
10
12
  module Bunny
11
13
 
12
- class ConnectionError < StandardError; end
13
- class ForcedChannelCloseError < StandardError; end
14
- class ForcedConnectionCloseError < StandardError; end
15
- class MessageError < StandardError; end
16
- class ProtocolError < StandardError; end
17
- class ServerDownError < StandardError; end
18
- class UnsubscribeError < StandardError; end
19
- class AcknowledgementError < StandardError; end
20
-
21
- # Returns the Bunny version number
22
-
23
- def self.version
24
- VERSION
25
- end
26
-
27
- # Instantiates new Bunny::Client
28
-
29
- def self.new(opts = {})
30
- # Set up Bunny according to AMQP spec version required
31
- spec_version = opts[:spec] || '08'
32
-
33
- # Return client
34
- setup(spec_version, opts)
35
- end
36
-
37
- # Runs a code block using a short-lived connection
14
+ class ConnectionError < StandardError; end
15
+ class ForcedChannelCloseError < StandardError; end
16
+ class ForcedConnectionCloseError < StandardError; end
17
+ class MessageError < StandardError; end
18
+ class ProtocolError < StandardError; end
19
+ class ServerDownError < StandardError; end
20
+ class UnsubscribeError < StandardError; end
21
+ class AcknowledgementError < StandardError; end
22
+
23
+ # Returns the Bunny version number
24
+
25
+ def self.version
26
+ VERSION
27
+ end
28
+
29
+ # Print deprecation warning.
30
+ def self.deprecation_warning(method, version)
31
+ warn "~ #{method} will be removed in Bunny #{version}."
32
+ end
33
+
34
+ # Instantiates new Bunny::Client
35
+
36
+ def self.new(connection_string_or_opts = Hash.new, opts = Hash.new)
37
+ # Set up Bunny according to AMQP spec version required
38
+ if connection_string_or_opts.respond_to?(:keys) && opts.empty?
39
+ opts = connection_string_or_opts
40
+ end
41
+
42
+ spec_version = opts[:spec] || '08'
43
+
44
+ # Return client
45
+ setup(spec_version, connection_string_or_opts, opts)
46
+ end
47
+
48
+ # Runs a code block using a short-lived connection
38
49
 
39
50
  def self.run(opts = {}, &block)
40
51
  raise ArgumentError, 'Bunny#run requires a block' unless block
41
52
 
42
- # Set up Bunny according to AMQP spec version required
43
- spec_version = opts[:spec] || '08'
44
- client = setup(spec_version, opts)
45
-
53
+ # Set up Bunny according to AMQP spec version required
54
+ spec_version = opts[:spec] || '08'
55
+ client = setup(spec_version, opts)
56
+
46
57
  begin
47
58
  client.start
48
59
  block.call(client)
@@ -50,38 +61,49 @@ module Bunny
50
61
  client.stop
51
62
  end
52
63
 
53
- # Return success
54
- :run_ok
64
+ # Return success
65
+ :run_ok
55
66
  end
56
67
 
57
- private
58
-
59
- def self.setup(version, opts)
60
- if version == '08'
61
- # AMQP 0-8 specification
62
- require 'qrack/qrack08'
63
- require 'bunny/client08'
64
- require 'bunny/exchange08'
65
- require 'bunny/queue08'
66
- require 'bunny/channel08'
67
- require 'bunny/subscription08'
68
-
69
- client = Bunny::Client.new(opts)
70
- else
71
- # AMQP 0-9-1 specification
72
- require 'qrack/qrack09'
73
- require 'bunny/client09'
74
- require 'bunny/exchange09'
75
- require 'bunny/queue09'
76
- require 'bunny/channel09'
77
- require 'bunny/subscription09'
78
-
79
- client = Bunny::Client09.new(opts)
80
- end
81
-
82
- include Qrack
68
+ Timer = if RUBY_VERSION < "1.9"
69
+ begin
70
+ require 'system_timer'
71
+ SystemTimer
72
+ rescue LoadError
73
+ Timeout
74
+ end
75
+ else
76
+ Timeout
77
+ end
78
+
79
+ private
80
+
81
+ def self.setup(version, *args)
82
+ if version == '08'
83
+ # AMQP 0-8 specification
84
+ require 'qrack/qrack08'
85
+ require 'bunny/client08'
86
+ require 'bunny/exchange08'
87
+ require 'bunny/queue08'
88
+ require 'bunny/channel08'
89
+ require 'bunny/subscription08'
90
+
91
+ client = Bunny::Client.new(*args)
92
+ else
93
+ # AMQP 0-9-1 specification
94
+ require 'qrack/qrack09'
95
+ require 'bunny/client09'
96
+ require 'bunny/exchange09'
97
+ require 'bunny/queue09'
98
+ require 'bunny/channel09'
99
+ require 'bunny/subscription09'
100
+
101
+ client = Bunny::Client09.new(*args)
102
+ end
103
+
104
+ include Qrack
83
105
 
84
106
  client
85
- end
107
+ end
86
108
 
87
- end
109
+ end
@@ -1,39 +1,39 @@
1
+ # encoding: utf-8
2
+
1
3
  module Bunny
2
- class Channel < Qrack::Channel
3
-
4
- def initialize(client)
5
- super
6
- end
7
-
8
- def open
9
- client.channel = self
10
- client.send_frame(Qrack::Protocol::Channel::Open.new)
11
-
12
- method = client.next_method
13
-
14
- client.check_response(method, Qrack::Protocol::Channel::OpenOk, "Cannot open channel #{number}")
15
-
16
- @active = true
17
- :open_ok
18
- end
19
-
20
- def close
21
- client.channel = self
22
- client.send_frame(
23
- Qrack::Protocol::Channel::Close.new(:reply_code => 200, :reply_text => 'bye', :method_id => 0, :class_id => 0)
24
- )
25
-
26
- method = client.next_method
27
-
28
- client.check_response(method, Qrack::Protocol::Channel::CloseOk, "Error closing channel #{number}")
29
-
30
- @active = false
31
- :close_ok
32
- end
33
-
34
- def open?
35
- active
36
- end
37
-
38
- end
39
- end
4
+ class Channel < Qrack::Channel
5
+
6
+ def initialize(client)
7
+ super
8
+ end
9
+
10
+ def open
11
+ client.channel = self
12
+ client.send_frame(Qrack::Protocol::Channel::Open.new)
13
+
14
+ method = client.next_method
15
+
16
+ client.check_response(method, Qrack::Protocol::Channel::OpenOk, "Cannot open channel #{number}")
17
+
18
+ @active = true
19
+ :open_ok
20
+ end
21
+
22
+ def close
23
+ client.channel = self
24
+ client.send_frame(Qrack::Protocol::Channel::Close.new(:reply_code => 200, :reply_text => 'bye', :method_id => 0, :class_id => 0))
25
+
26
+ method = client.next_method
27
+
28
+ client.check_response(method, Qrack::Protocol::Channel::CloseOk, "Error closing channel #{number}")
29
+
30
+ @active = false
31
+ :close_ok
32
+ end
33
+
34
+ def open?
35
+ active
36
+ end
37
+
38
+ end
39
+ end
@@ -1,39 +1,39 @@
1
+ # encoding: utf-8
2
+
1
3
  module Bunny
2
- class Channel09 < Qrack::Channel
3
-
4
- def initialize(client)
5
- super
6
- end
7
-
8
- def open
9
- client.channel = self
10
- client.send_frame(Qrack::Protocol09::Channel::Open.new)
11
-
4
+ class Channel09 < Qrack::Channel
5
+
6
+ def initialize(client)
7
+ super
8
+ end
9
+
10
+ def open
11
+ client.channel = self
12
+ client.send_frame(Qrack::Protocol09::Channel::Open.new)
13
+
12
14
  method = client.next_method
13
-
14
- client.check_response(method, Qrack::Protocol09::Channel::OpenOk, "Cannot open channel #{number}")
15
-
16
- @active = true
17
- :open_ok
18
- end
19
-
20
- def close
21
- client.channel = self
22
- client.send_frame(
23
- Qrack::Protocol09::Channel::Close.new(:reply_code => 200, :reply_text => 'bye', :method_id => 0, :class_id => 0)
24
- )
25
-
26
- method = client.next_method
27
-
28
- client.check_response(method, Qrack::Protocol09::Channel::CloseOk, "Error closing channel #{number}")
29
-
30
- @active = false
31
- :close_ok
32
- end
33
-
34
- def open?
35
- active
36
- end
37
-
38
- end
39
- end
15
+
16
+ client.check_response(method, Qrack::Protocol09::Channel::OpenOk, "Cannot open channel #{number}")
17
+
18
+ @active = true
19
+ :open_ok
20
+ end
21
+
22
+ def close
23
+ client.channel = self
24
+ client.send_frame(Qrack::Protocol09::Channel::Close.new(:reply_code => 200, :reply_text => 'bye', :method_id => 0, :class_id => 0))
25
+
26
+ method = client.next_method
27
+
28
+ client.check_response(method, Qrack::Protocol09::Channel::CloseOk, "Error closing channel #{number}")
29
+
30
+ @active = false
31
+ :close_ok
32
+ end
33
+
34
+ def open?
35
+ active
36
+ end
37
+
38
+ end
39
+ end
@@ -1,5 +1,7 @@
1
+ # encoding: utf-8
2
+
1
3
  module Bunny
2
-
4
+
3
5
  =begin rdoc
4
6
 
5
7
  === DESCRIPTION:
@@ -9,8 +11,8 @@ The Client class provides the major Bunny API methods.
9
11
  =end
10
12
 
11
13
  class Client < Qrack::Client
12
-
13
- attr_accessor :ticket
14
+
15
+ attr_accessor :ticket
14
16
 
15
17
  =begin rdoc
16
18
 
@@ -46,10 +48,10 @@ Sets up a Bunny::Client object ready for connection to a broker/server. _Client_
46
48
 
47
49
  =end
48
50
 
49
- def initialize(opts = {})
50
- super
51
- @spec = '0-8'
52
- @port = opts[:port] || (opts[:ssl] ? Qrack::Protocol::SSL_PORT : Qrack::Protocol::PORT)
51
+ def initialize(connection_string_or_opts = Hash.new, opts = Hash.new)
52
+ super
53
+ @spec = '0-8'
54
+ @port = opts[:port] || (opts[:ssl] ? Qrack::Protocol::SSL_PORT : Qrack::Protocol::PORT)
53
55
  @insist = opts[:insist]
54
56
  end
55
57
 
@@ -61,51 +63,46 @@ Checks response from AMQP methods and takes appropriate action
61
63
 
62
64
  =end
63
65
 
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
-
88
- def close_connection
89
- # Set client channel to zero
66
+ def check_response(received_method, expected_method, err_msg, err_class = Bunny::ProtocolError)
67
+ case
68
+ when received_method.is_a?(Qrack::Protocol::Connection::Close)
69
+ # Clean up the socket
70
+ close_socket
71
+
72
+ raise Bunny::ForcedConnectionCloseError, "Error Reply Code: #{received_method.reply_code}\nError Reply Text: #{received_method.reply_text}"
73
+
74
+ when received_method.is_a?(Qrack::Protocol::Channel::Close)
75
+ # Clean up the channel
76
+ channel.active = false
77
+
78
+ raise Bunny::ForcedChannelCloseError, "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
+
88
+ def close_connection
89
+ # Set client channel to zero
90
90
  switch_channel(0)
91
-
92
- send_frame(
93
- Qrack::Protocol::Connection::Close.new(:reply_code => 200, :reply_text => 'Goodbye', :class_id => 0, :method_id => 0)
94
- )
95
-
96
- method = next_method
97
-
98
- check_response(method, Qrack::Protocol::Connection::CloseOk, "Error closing connection")
99
-
91
+
92
+ send_frame(Qrack::Protocol::Connection::Close.new(:reply_code => 200, :reply_text => 'Goodbye', :class_id => 0, :method_id => 0))
93
+
94
+ method = next_method
95
+
96
+ check_response(method, Qrack::Protocol::Connection::CloseOk, "Error closing connection")
100
97
  end
101
98
 
102
- def create_channel
103
- channels.each do |c|
104
- return c if (!c.open? and c.number != 0)
105
- end
106
- # If no channel to re-use instantiate new one
107
- Bunny::Channel.new(self)
108
- end
99
+ def create_channel
100
+ channels.each do |c|
101
+ return c if (!c.open? and c.number != 0)
102
+ end
103
+ # If no channel to re-use instantiate new one
104
+ Bunny::Channel.new(self)
105
+ end
109
106
 
110
107
  =begin rdoc
111
108
 
@@ -133,92 +130,82 @@ Exchange
133
130
 
134
131
  =end
135
132
 
136
- def exchange(name, opts = {})
133
+ def exchange(name, opts = {})
137
134
  exchanges[name] || Bunny::Exchange.new(self, name, opts)
138
- end
139
-
140
- def init_connection
141
- write(Qrack::Protocol::HEADER)
135
+ end
136
+
137
+ def init_connection
138
+ write(Qrack::Protocol::HEADER)
142
139
  write([1, 1, Qrack::Protocol::VERSION_MAJOR, Qrack::Protocol::VERSION_MINOR].pack('C4'))
143
140
 
144
- frame = next_frame
145
- if frame.nil? or !frame.payload.is_a?(Qrack::Protocol::Connection::Start)
146
- raise Bunny::ProtocolError, 'Connection initiation failed'
147
- end
148
- end
149
-
150
- def next_frame(opts = {})
141
+ frame = next_frame
142
+ if frame.nil? or !frame.payload.is_a?(Qrack::Protocol::Connection::Start)
143
+ raise Bunny::ProtocolError, 'Connection initiation failed'
144
+ end
145
+ end
146
+
147
+ def next_frame(opts = {})
151
148
  frame = nil
152
-
153
- case
154
- when channel.frame_buffer.size > 0
155
- frame = channel.frame_buffer.shift
156
- when opts.has_key?(:timeout)
157
- Timeout::timeout(opts[:timeout], Qrack::ClientTimeout) do
158
- frame = Qrack::Transport::Frame.parse(buffer)
159
- end
160
- else
161
- frame = Qrack::Transport::Frame.parse(buffer)
149
+
150
+ case
151
+ when channel.frame_buffer.size > 0
152
+ frame = channel.frame_buffer.shift
153
+ when (timeout = opts[:timeout]) && timeout > 0
154
+ Bunny::Timer::timeout(timeout, Qrack::ClientTimeout) do
155
+ frame = Qrack::Transport::Frame.parse(buffer)
156
+ end
157
+ else
158
+ frame = Qrack::Transport::Frame.parse(buffer)
159
+ end
160
+
161
+ @logger.info("received") { frame } if @logging
162
+
163
+ raise Bunny::ConnectionError, 'No connection to server' if (frame.nil? and !connecting?)
164
+
165
+ # Monitor server activity and discard heartbeats
166
+ @message_in = true
167
+
168
+ case
169
+ when frame.is_a?(Qrack::Transport::Heartbeat)
170
+ next_frame(opts)
171
+ when frame.nil?
172
+ frame
173
+ when ((frame.channel != channel.number) and (frame.channel != 0))
174
+ channel.frame_buffer << frame
175
+ next_frame(opts)
176
+ else
177
+ frame
162
178
  end
163
-
164
- @logger.info("received") { frame } if @logging
165
-
166
- raise Bunny::ConnectionError, 'No connection to server' if (frame.nil? and !connecting?)
167
-
168
- # Monitor server activity and discard heartbeats
169
- @message_in = true
170
-
171
- case
172
- when frame.is_a?(Qrack::Transport::Heartbeat)
173
- next_frame(opts)
174
- when frame.nil?
175
- frame
176
- when ((frame.channel != channel.number) and (frame.channel != 0))
177
- channel.frame_buffer << frame
178
- next_frame(opts)
179
- else
180
- frame
181
- end
182
-
183
179
  end
184
180
 
185
- def open_connection
186
- send_frame(
187
- Qrack::Protocol::Connection::StartOk.new(
188
- {:platform => 'Ruby', :product => 'Bunny', :information => 'http://github.com/celldee/bunny', :version => VERSION},
189
- 'AMQPLAIN',
190
- {:LOGIN => @user, :PASSWORD => @pass},
191
- 'en_US'
192
- )
193
- )
181
+ def open_connection
182
+ client_opts = { :platform => 'Ruby', :product => 'Bunny', :information => 'http://github.com/ruby-amqp/bunny', :version => VERSION }
183
+
184
+ send_frame(Qrack::Protocol::Connection::StartOk.new(client_opts, 'AMQPLAIN', {:LOGIN => @user, :PASSWORD => @pass}, 'en_US'))
194
185
 
195
186
  frame = next_frame
196
- raise Bunny::ProtocolError, "Connection failed - user: #{@user}" if frame.nil?
197
-
198
- method = frame.payload
187
+ raise Bunny::ProtocolError, "Connection failed - user: #{@user}" if frame.nil?
188
+
189
+ method = frame.payload
199
190
 
200
191
  if method.is_a?(Qrack::Protocol::Connection::Tune)
201
- send_frame(
202
- Qrack::Protocol::Connection::TuneOk.new( :channel_max => @channel_max, :frame_max => @frame_max, :heartbeat => @heartbeat)
203
- )
192
+ send_frame(Qrack::Protocol::Connection::TuneOk.new( :channel_max => @channel_max, :frame_max => @frame_max, :heartbeat => @heartbeat))
204
193
  end
205
194
 
206
- send_frame(
207
- Qrack::Protocol::Connection::Open.new(:virtual_host => @vhost, :capabilities => '', :insist => @insist)
208
- )
195
+ send_frame(Qrack::Protocol::Connection::Open.new(:virtual_host => @vhost, :capabilities => '', :insist => @insist))
209
196
 
210
197
  case method = next_method
211
198
  when Qrack::Protocol::Connection::OpenOk
212
199
  :ok
213
200
  when Qrack::Protocol::Connection::Redirect
214
- raise Bunny::ConnectionError, "Cannot connect to the specified server - host: #{@host}, port: #{@port}" if @insist
215
-
201
+ raise Bunny::ConnectionError, "Cannot connect to the specified server - host: #{@host}, port: #{@port}" if @insist
202
+
216
203
  @host, @port = method.host.split(':')
217
204
  close_socket
218
205
  else
219
206
  raise Bunny::ProtocolError, 'Cannot open connection'
220
207
  end
221
- end
208
+ end
222
209
 
223
210
  =begin rdoc
224
211
 
@@ -252,15 +239,12 @@ true, they are applied to the entire connection.
252
239
 
253
240
  =end
254
241
 
255
- def qos(opts = {})
242
+ def qos(opts = {})
243
+ send_frame(Qrack::Protocol::Basic::Qos.new({ :prefetch_size => 0, :prefetch_count => 1, :global => false }.merge(opts)))
256
244
 
257
- send_frame(
258
- Qrack::Protocol::Basic::Qos.new({ :prefetch_size => 0, :prefetch_count => 1, :global => false }.merge(opts))
259
- )
245
+ method = next_method
260
246
 
261
- method = next_method
262
-
263
- check_response(method, Qrack::Protocol::Basic::QosOk, "Error specifying Quality of Service")
247
+ check_response(method, Qrack::Protocol::Basic::QosOk, "Error specifying Quality of Service")
264
248
 
265
249
  # return confirmation
266
250
  :qos_ok
@@ -280,7 +264,7 @@ occurs a _Bunny_::_ProtocolError_ is raised.
280
264
  * <tt>:passive => true or false (_default_)</tt> - If set to _true_, the server will not create
281
265
  the queue. The client can use this to check whether a queue exists without modifying the server
282
266
  state.
283
- * <tt>:durable => true or false (_default_)</tt> - If set to _true_ when creating a new queue, the
267
+ * <tt>:durable => true or false (_default_)</tt> - If set to _true_ when creating a new queue, the
284
268
  queue will be marked as durable. Durable queues remain active when a server restarts. Non-durable
285
269
  queues (transient queues) are purged if/when a server restarts. Note that durable queues do not
286
270
  necessarily hold persistent messages, although it does not make sense to send persistent messages
@@ -288,8 +272,8 @@ occurs a _Bunny_::_ProtocolError_ is raised.
288
272
  * <tt>:exclusive => true or false (_default_)</tt> - If set to _true_, requests an exclusive queue.
289
273
  Exclusive queues may only be consumed from by the current connection. Setting the 'exclusive'
290
274
  flag always implies 'auto-delete'.
291
- * <tt>:auto_delete => true or false (_default_)</tt> - If set to _true_, the queue is deleted
292
- when all consumers have finished using it. Last consumer can be cancelled either explicitly
275
+ * <tt>:auto_delete => true or false (_default_)</tt> - If set to _true_, the queue is deleted
276
+ when all consumers have finished using it. Last consumer can be cancelled either explicitly
293
277
  or because its channel is closed. If there has never been a consumer on the queue, it is not
294
278
  deleted.
295
279
  * <tt>:nowait => true or false (_default_)</tt> - Ignored by Bunny, always _false_.
@@ -299,8 +283,8 @@ occurs a _Bunny_::_ProtocolError_ is raised.
299
283
  Queue
300
284
 
301
285
  =end
302
-
303
- def queue(name = nil, opts = {})
286
+
287
+ def queue(name = nil, opts = {})
304
288
  if name.is_a?(Hash)
305
289
  opts = name
306
290
  name = nil
@@ -308,7 +292,7 @@ Queue
308
292
 
309
293
  # Queue is responsible for placing itself in the list of queues
310
294
  queues[name] || Bunny::Queue.new(self, name, opts)
311
- end
295
+ end
312
296
 
313
297
  =begin rdoc
314
298
 
@@ -325,27 +309,21 @@ the message, potentially then delivering it to an alternative subscriber.
325
309
 
326
310
  =end
327
311
 
328
- def recover(opts = {})
329
-
330
- send_frame(
331
- Qrack::Protocol::Basic::Recover.new({ :requeue => false }.merge(opts))
332
- )
312
+ def recover(opts = {})
313
+ send_frame(Qrack::Protocol::Basic::Recover.new({ :requeue => false }.merge(opts)))
314
+ end
333
315
 
334
- end
335
-
336
- def request_access
337
- send_frame(
338
- Qrack::Protocol::Access::Request.new(:realm => '/data', :read => true, :write => true, :active => true, :passive => true)
339
- )
316
+ def request_access
317
+ send_frame(Qrack::Protocol::Access::Request.new(:realm => '/data', :read => true, :write => true, :active => true, :passive => true))
340
318
 
341
319
  method = next_method
342
-
343
- check_response(method, Qrack::Protocol::Access::RequestOk, "Access denied")
344
-
320
+
321
+ check_response(method, Qrack::Protocol::Access::RequestOk, "Access denied")
322
+
345
323
  self.ticket = method.ticket
346
- end
347
-
348
- def send_frame(*args)
324
+ end
325
+
326
+ def send_frame(*args)
349
327
  args.each do |data|
350
328
  data.ticket = ticket if ticket and data.respond_to?(:ticket=)
351
329
  data = data.to_frame(channel.number) unless data.is_a?(Qrack::Transport::Frame)
@@ -354,21 +332,21 @@ the message, potentially then delivering it to an alternative subscriber.
354
332
  @logger.info("send") { data } if @logging
355
333
  write(data.to_s)
356
334
 
357
- # Monitor client activity for heartbeat purposes
358
- @message_out = true
335
+ # Monitor client activity for heartbeat purposes
336
+ @message_out = true
359
337
  end
360
338
 
361
339
  nil
362
340
  end
363
-
364
- def send_heartbeat
365
- # Create a new heartbeat frame
366
- hb = Qrack::Transport::Heartbeat.new('')
367
- # Channel 0 must be used
368
- switch_channel(0) if @channel.number > 0
369
- # Send the heartbeat to server
370
- send_frame(hb)
371
- end
341
+
342
+ def send_heartbeat
343
+ # Create a new heartbeat frame
344
+ hb = Qrack::Transport::Heartbeat.new('')
345
+ # Channel 0 must be used
346
+ switch_channel(0) if @channel.number > 0
347
+ # Send the heartbeat to server
348
+ send_frame(hb)
349
+ end
372
350
 
373
351
  =begin rdoc
374
352
 
@@ -382,36 +360,36 @@ _Bunny_::_ProtocolError_ is raised. If successful, _Client_._status_ is set to <
382
360
  <tt>:connected</tt> if successful.
383
361
 
384
362
  =end
385
-
386
- def start_session
387
- @connecting = true
388
-
363
+
364
+ def start_session
365
+ @connecting = true
366
+
389
367
  loop do
390
- # Create/get socket
391
- socket
392
-
393
- # Initiate connection
394
- init_connection
395
-
396
- # Open connection
397
- break if open_connection == :ok
368
+ # Create/get socket
369
+ socket
370
+
371
+ # Initiate connection
372
+ init_connection
373
+
374
+ # Open connection
375
+ break if open_connection == :ok
398
376
  end
399
377
 
400
- # Open another channel because channel zero is used for specific purposes
401
- c = create_channel()
402
- c.open
403
-
404
- # Get access ticket
405
- request_access
406
-
407
- @connecting = false
408
-
409
- # return status
410
- @status = :connected
378
+ # Open another channel because channel zero is used for specific purposes
379
+ c = create_channel()
380
+ c.open
381
+
382
+ # Get access ticket
383
+ request_access
384
+
385
+ @connecting = false
386
+
387
+ # return status
388
+ @status = :connected
411
389
  end
412
390
 
413
- alias start start_session
414
-
391
+ alias start start_session
392
+
415
393
  =begin rdoc
416
394
 
417
395
  === DESCRIPTION:
@@ -425,17 +403,17 @@ after a commit.
425
403
 
426
404
  =end
427
405
 
428
- def tx_commit
429
- send_frame(Qrack::Protocol::Tx::Commit.new())
430
-
431
- method = next_method
432
-
433
- check_response(method, Qrack::Protocol::Tx::CommitOk, "Error commiting transaction")
434
-
435
- # return confirmation
436
- :commit_ok
437
- end
438
-
406
+ def tx_commit
407
+ send_frame(Qrack::Protocol::Tx::Commit.new())
408
+
409
+ method = next_method
410
+
411
+ check_response(method, Qrack::Protocol::Tx::CommitOk, "Error commiting transaction")
412
+
413
+ # return confirmation
414
+ :commit_ok
415
+ end
416
+
439
417
  =begin rdoc
440
418
 
441
419
  === DESCRIPTION:
@@ -449,16 +427,16 @@ after a rollback.
449
427
 
450
428
  =end
451
429
 
452
- def tx_rollback
453
- send_frame(Qrack::Protocol::Tx::Rollback.new())
430
+ def tx_rollback
431
+ send_frame(Qrack::Protocol::Tx::Rollback.new())
454
432
 
455
- method = next_method
456
-
457
- check_response(method, Qrack::Protocol::Tx::RollbackOk, "Error rolling back transaction")
433
+ method = next_method
434
+
435
+ check_response(method, Qrack::Protocol::Tx::RollbackOk, "Error rolling back transaction")
458
436
 
459
- # return confirmation
460
- :rollback_ok
461
- end
437
+ # return confirmation
438
+ :rollback_ok
439
+ end
462
440
 
463
441
  =begin rdoc
464
442
 
@@ -473,18 +451,18 @@ using the Commit or Rollback methods.
473
451
 
474
452
  =end
475
453
 
476
- def tx_select
477
- send_frame(Qrack::Protocol::Tx::Select.new())
454
+ def tx_select
455
+ send_frame(Qrack::Protocol::Tx::Select.new())
478
456
 
479
- method = next_method
480
-
481
- check_response(method, Qrack::Protocol::Tx::SelectOk, "Error initiating transactions for current channel")
457
+ method = next_method
458
+
459
+ check_response(method, Qrack::Protocol::Tx::SelectOk, "Error initiating transactions for current channel")
482
460
 
483
- # return confirmation
484
- :select_ok
485
- end
461
+ # return confirmation
462
+ :select_ok
463
+ end
486
464
 
487
- private
465
+ private
488
466
 
489
467
  def buffer
490
468
  @buffer ||= Qrack::Transport::Buffer.new(self)