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,290 +1,249 @@
1
- module Bunny
2
-
3
- =begin rdoc
4
-
5
- === DESCRIPTION:
1
+ # encoding: utf-8
6
2
 
7
- The Client class provides the major Bunny API methods.
8
-
9
- =end
3
+ module Bunny
10
4
 
5
+ # The Client class provides the major Bunny API methods.
11
6
  class Client09 < Qrack::Client
12
7
 
13
- =begin rdoc
14
-
15
- === DESCRIPTION:
16
-
17
- Sets up a Bunny::Client object ready for connection to a broker/server. _Client_._status_ is set to
18
- <tt>:not_connected</tt>.
19
-
20
- ==== OPTIONS:
21
-
22
- * <tt>:host => '_hostname_' (default = 'localhost')</tt>
23
- * <tt>:port => _portno_ (default = 5672 or 5671 if :ssl set to true)</tt>
24
- * <tt>:vhost => '_vhostname_' (default = '/')</tt>
25
- * <tt>:user => '_username_' (default = 'guest')</tt>
26
- * <tt>:pass => '_password_' (default = 'guest')</tt>
27
- * <tt>:ssl => true or false (default = false)</tt> - If set to _true_, ssl
28
- encryption will be used and port will default to 5671.
29
- * <tt>:verify_ssl => true or false (default = true)</tt> - If ssl is enabled,
30
- this will cause OpenSSL to validate the server certificate unless this
31
- parameter is set to _false_.
32
- * <tt>:logfile => '_logfilepath_' (default = nil)</tt>
33
- * <tt>:logging => true or false (_default_)</tt> - If set to _true_, session information is sent
34
- to STDOUT if <tt>:logfile</tt> has not been specified. Otherwise, session information is written to
35
- <tt>:logfile</tt>.
36
- * <tt>:frame_max => maximum frame size in bytes (default = 131072)</tt>
37
- * <tt>:channel_max => maximum number of channels (default = 0 no maximum)</tt>
38
- * <tt>:heartbeat => number of seconds (default = 0 no heartbeat)</tt>
39
- * <tt>:connect_timeout => number of seconds before Qrack::ConnectionTimeout is raised (default = 5)</tt>
40
-
41
- =end
42
-
43
- def initialize(opts = {})
44
- super
45
- @spec = '0-9-1'
46
- @port = opts[:port] || (opts[:ssl] ? Qrack::Protocol09::SSL_PORT : Qrack::Protocol09::PORT)
8
+ # Sets up a Bunny::Client object ready for connection to a broker.
9
+ # {Client.status} is set to @:not_connected@.
10
+ #
11
+ # @option opts [String] :host ("localhost")
12
+ # @option opts [Integer] :port (5672 or 5671 if :ssl set to true)
13
+ # @option opts [String] :vhost ("/")
14
+ # @option opts [String] :user ("guest")
15
+ # @option opts [String] :pass ("guest")
16
+ # @option opts [Boolean] :ssl (false)
17
+ # If set to @true@, ssl encryption will be used and port will default to 5671.
18
+ # @option opts [Boolean] :verify_ssl (true)
19
+ # If ssl is enabled, this will cause OpenSSL to validate
20
+ # the server certificate unless this parameter is set to @false@.
21
+ # @option opts [String] :logfile (nil)
22
+ # @option opts [Boolean] :logging (false)
23
+ # If set to @true@, session information is sent to STDOUT if @:logfile@
24
+ # has not been specified. Otherwise, session information is written to @:logfile@.
25
+ # @option opts [Integer] :frame_max (131072)
26
+ # Maximum frame size in bytes.
27
+ # @option opts [Integer] :channel_max (0)
28
+ # Maximum number of channels. Defaults to 0 which means no maximum.
29
+ # @option opts [Integer] :heartbeat (0)
30
+ # Number of seconds. Defaults to 0 which means no heartbeat.
31
+ # @option opts [Integer] :connect_timeout (5)
32
+ # Number of seconds before {Qrack::ConnectionTimeout} is raised.@
33
+ def initialize(connection_string_or_opts = Hash.new, opts = Hash.new)
34
+ super
35
+ @spec = '0-9-1'
36
+ @port = opts[:port] || (opts[:ssl] ? Qrack::Protocol09::SSL_PORT : Qrack::Protocol09::PORT)
47
37
  end
48
38
 
49
- =begin rdoc
50
-
51
- === DESCRIPTION:
52
-
53
- Checks response from AMQP methods and takes appropriate action
54
-
55
- =end
39
+ # Checks response from AMQP methods and takes appropriate action
40
+ def check_response(received_method, expected_method, err_msg, err_class = Bunny::ProtocolError)
41
+ case
42
+ when received_method.is_a?(Qrack::Protocol09::Connection::Close)
43
+ # Clean up the socket
44
+ close_socket
56
45
 
57
- def check_response(received_method, expected_method, err_msg, err_class = Bunny::ProtocolError)
58
- case
59
- when received_method.is_a?(Qrack::Protocol09::Connection::Close)
60
- # Clean up the socket
61
- close_socket
46
+ raise Bunny::ForcedConnectionCloseError, "Error Reply Code: #{received_method.reply_code}\nError Reply Text: #{received_method.reply_text}"
62
47
 
63
- raise Bunny::ForcedConnectionCloseError,
64
- "Error Reply Code: #{received_method.reply_code}\nError Reply Text: #{received_method.reply_text}"
48
+ when received_method.is_a?(Qrack::Protocol09::Channel::Close)
49
+ # Clean up the channel
50
+ channel.active = false
65
51
 
66
- when received_method.is_a?(Qrack::Protocol09::Channel::Close)
67
- # Clean up the channel
68
- channel.active = false
52
+ raise Bunny::ForcedChannelCloseError, "Error Reply Code: #{received_method.reply_code}\nError Reply Text: #{received_method.reply_text}"
69
53
 
70
- raise Bunny::ForcedChannelCloseError,
71
- "Error Reply Code: #{received_method.reply_code}\nError Reply Text: #{received_method.reply_text}"
54
+ when !received_method.is_a?(expected_method)
55
+ raise err_class, err_msg
72
56
 
73
- when !received_method.is_a?(expected_method)
74
- raise err_class, err_msg
75
-
76
- else
77
- :response_ok
78
- end
79
- end
57
+ else
58
+ :response_ok
59
+ end
60
+ end
80
61
 
81
- def close_connection
82
- # Set client channel to zero
62
+ def close_connection
63
+ # Set client channel to zero
83
64
  switch_channel(0)
84
65
 
85
- send_frame(
86
- Qrack::Protocol09::Connection::Close.new(:reply_code => 200, :reply_text => 'Goodbye', :class_id => 0, :method_id => 0)
87
- )
66
+ send_frame(Qrack::Protocol09::Connection::Close.new(:reply_code => 200, :reply_text => 'Goodbye', :class_id => 0, :method_id => 0))
88
67
 
89
68
  method = next_method
90
-
91
- check_response(method, Qrack::Protocol09::Connection::CloseOk, "Error closing connection")
92
-
93
- end
94
-
95
- def create_channel
96
- channels.each do |c|
97
- return c if (!c.open? and c.number != 0)
98
- end
99
- # If no channel to re-use instantiate new one
100
- Bunny::Channel09.new(self)
101
- end
102
-
103
- =begin rdoc
104
-
105
- === DESCRIPTION:
106
-
107
- Declares an exchange to the broker/server. If the exchange does not exist, a new one is created
108
- using the arguments passed in. If the exchange already exists, a reference to it is created, provided
109
- that the arguments passed in do not conflict with the existing attributes of the exchange. If an error
110
- occurs a _Bunny_::_ProtocolError_ is raised.
111
69
 
112
- ==== OPTIONS:
70
+ check_response(method, Qrack::Protocol09::Connection::CloseOk, "Error closing connection")
113
71
 
114
- * <tt>:type => one of :direct (_default_), :fanout, :topic, :headers</tt>
115
- * <tt>:passive => true or false</tt> - If set to _true_, the server will not create the exchange.
116
- The client can use this to check whether an exchange exists without modifying the server state.
117
- * <tt>:durable => true or false (_default_)</tt> - If set to _true_ when creating a new exchange, the exchange
118
- will be marked as durable. Durable exchanges remain active when a server restarts. Non-durable
119
- exchanges (transient exchanges) are purged if/when a server restarts.
120
- * <tt>:auto_delete => true or false (_default_)</tt> - If set to _true_, the exchange is deleted
121
- when all queues have finished using it.
122
- * <tt>:nowait => true or false (_default_)</tt> - Ignored by Bunny, always _false_.
123
-
124
- ==== RETURNS:
125
-
126
- Exchange
72
+ end
127
73
 
128
- =end
74
+ def create_channel
75
+ channels.each do |c|
76
+ return c if (!c.open? and c.number != 0)
77
+ end
78
+ # If no channel to re-use instantiate new one
79
+ Bunny::Channel09.new(self)
80
+ end
129
81
 
130
- def exchange(name, opts = {})
82
+ # Declares an exchange to the broker/server. If the exchange does not exist, a new one is created
83
+ # using the arguments passed in. If the exchange already exists, a reference to it is created, provided
84
+ # that the arguments passed in do not conflict with the existing attributes of the exchange. If an error
85
+ # occurs a _Bunny_::_ProtocolError_ is raised.
86
+ #
87
+ # @option opts [Symbol] :type (:direct)
88
+ # One of :direct@, @:fanout@, @:topic@, or @:headers@.
89
+ #
90
+ # @option opts [Boolean] :passive
91
+ # If set to @true@, the server will not create the exchange.
92
+ # The client can use this to check whether an exchange exists without modifying the server state.
93
+ #
94
+ # @option opts [Boolean] :durable (false)
95
+ # If set to @true@ when creating a new exchange, the exchange
96
+ # will be marked as durable. Durable exchanges remain active
97
+ # when a server restarts. Non-durable exchanges (transient exchanges)
98
+ # are purged if/when a server restarts.
99
+ #
100
+ # @option opts [Boolean] :auto_delete (false)
101
+ # If set to @true@, the exchange is deleted when all queues have finished using it.
102
+ #
103
+ # @option opts [Boolean] :nowait (false)
104
+ # Ignored by Bunny, always @false@.
105
+ #
106
+ # @return [Bunny::Exchange09]
107
+ def exchange(name, opts = {})
131
108
  exchanges[name] || Bunny::Exchange09.new(self, name, opts)
132
- end
133
-
134
- def init_connection
135
- write(Qrack::Protocol09::HEADER)
109
+ end
110
+
111
+ def init_connection
112
+ write(Qrack::Protocol09::HEADER)
136
113
  write([0, Qrack::Protocol09::VERSION_MAJOR, Qrack::Protocol09::VERSION_MINOR, Qrack::Protocol09::REVISION].pack('C4'))
137
114
 
138
115
  frame = next_frame
139
- if frame.nil? or !frame.payload.is_a?(Qrack::Protocol09::Connection::Start)
140
- raise Bunny::ProtocolError, 'Connection initiation failed'
141
- end
142
- end
143
-
144
- def next_frame(opts = {})
145
- frame = nil
146
-
147
- case
148
- when channel.frame_buffer.size > 0
149
- frame = channel.frame_buffer.shift
150
- when opts.has_key?(:timeout)
151
- Timeout::timeout(opts[:timeout], Qrack::ClientTimeout) do
152
- frame = Qrack::Transport09::Frame.parse(buffer)
153
- end
154
- else
155
- frame = Qrack::Transport09::Frame.parse(buffer)
116
+ if frame.nil? or !frame.payload.is_a?(Qrack::Protocol09::Connection::Start)
117
+ raise Bunny::ProtocolError, 'Connection initiation failed'
156
118
  end
157
-
158
- @logger.info("received") { frame } if @logging
159
-
160
- raise Bunny::ConnectionError, 'No connection to server' if (frame.nil? and !connecting?)
161
-
162
- # Monitor server activity and discard heartbeats
163
- @message_in = true
164
-
165
- case
166
- when frame.is_a?(Qrack::Transport09::Heartbeat)
167
- next_frame(opts)
168
- when frame.nil?
169
- frame
170
- when ((frame.channel != channel.number) and (frame.channel != 0))
171
- channel.frame_buffer << frame
172
- next_frame(opts)
173
- else
174
- frame
175
- end
176
-
177
119
  end
178
120
 
179
- def open_connection
180
- send_frame(
181
- Qrack::Protocol09::Connection::StartOk.new(
182
- :client_properties => {:platform => 'Ruby', :product => 'Bunny', :information => 'http://github.com/celldee/bunny', :version => VERSION},
183
- :mechanism => 'PLAIN',
184
- :response => "\0" + @user + "\0" + @pass,
185
- :locale => 'en_US'
186
- )
187
- )
121
+ def next_frame(opts = {})
122
+ frame = nil
188
123
 
189
- frame = next_frame
190
- raise Bunny::ProtocolError, "Connection failed - user: #{@user}" if frame.nil?
191
-
192
- method = frame.payload
193
-
194
- if method.is_a?(Qrack::Protocol09::Connection::Tune)
195
- send_frame(
196
- Qrack::Protocol09::Connection::TuneOk.new( :channel_max => @channel_max, :frame_max => @frame_max, :heartbeat => @heartbeat)
197
- )
124
+ case
125
+ when channel.frame_buffer.size > 0
126
+ frame = channel.frame_buffer.shift
127
+ when (timeout = opts[:timeout]) && timeout > 0
128
+ Bunny::Timer::timeout(timeout, Qrack::ClientTimeout) do
129
+ frame = Qrack::Transport09::Frame.parse(buffer)
130
+ end
131
+ else
132
+ frame = Qrack::Transport09::Frame.parse(buffer)
198
133
  end
199
134
 
200
- send_frame(
201
- Qrack::Protocol09::Connection::Open.new(:virtual_host => @vhost, :reserved_1 => 0, :reserved_2 => false)
202
- )
135
+ @logger.info("received") { frame } if @logging
203
136
 
204
- raise Bunny::ProtocolError, 'Cannot open connection' unless next_method.is_a?(Qrack::Protocol09::Connection::OpenOk)
205
- end
137
+ raise Bunny::ConnectionError, 'No connection to server' if (frame.nil? and !connecting?)
206
138
 
207
- =begin rdoc
139
+ # Monitor server activity and discard heartbeats
140
+ @message_in = true
208
141
 
209
- === DESCRIPTION:
142
+ case
143
+ when frame.is_a?(Qrack::Transport09::Heartbeat)
144
+ next_frame(opts)
145
+ when frame.nil?
146
+ frame
147
+ when ((frame.channel != channel.number) and (frame.channel != 0))
148
+ channel.frame_buffer << frame
149
+ next_frame(opts)
150
+ else
151
+ frame
152
+ end
210
153
 
211
- Requests a specific quality of service. The QoS can be specified for the current channel
212
- or for all channels on the connection. The particular properties and semantics of a QoS
213
- method always depend on the content class semantics. Though the QoS method could in principle
214
- apply to both peers, it is currently meaningful only for the server.
154
+ end
215
155
 
216
- ==== Options:
156
+ def open_connection
157
+ client_props = { :platform => 'Ruby', :product => 'Bunny', :information => 'http://github.com/ruby-amqp/bunny', :version => VERSION }
158
+ start_opts = {
159
+ :client_properties => client_props,
160
+ :mechanism => 'PLAIN',
161
+ :response => "\0" + @user + "\0" + @pass,
162
+ :locale => 'en_US'
163
+ }
164
+ send_frame(Qrack::Protocol09::Connection::StartOk.new(start_opts))
217
165
 
218
- * <tt>:prefetch_size => size in no. of octets (default = 0)</tt> - The client can request that
219
- messages be sent in advance so that when the client finishes processing a message, the following
220
- message is already held locally, rather than needing to be sent down the channel. Prefetching gives
221
- a performance improvement. This field specifies the prefetch window size in octets. The server
222
- will send a message in advance if it is equal to or smaller in size than the available prefetch
223
- size (and also falls into other prefetch limits). May be set to zero, meaning "no specific limit",
224
- although other prefetch limits may still apply. The prefetch-size is ignored if the no-ack option
225
- is set.
226
- * <tt>:prefetch_count => no. messages (default = 1)</tt> - Specifies a prefetch window in terms
227
- of whole messages. This field may be used in combination with the prefetch-size field; a message
228
- will only be sent in advance if both prefetch windows (and those at the channel and connection level)
229
- allow it. The prefetch-count is ignored if the no-ack option is set.
230
- * <tt>:global => true or false (_default_)</tt> - By default the QoS settings apply to the current channel only. If set to
231
- true, they are applied to the entire connection.
166
+ frame = next_frame
167
+ raise Bunny::ProtocolError, "Connection failed - user: #{@user}" if frame.nil?
232
168
 
233
- ==== RETURNS:
169
+ method = frame.payload
234
170
 
235
- <tt>:qos_ok</tt> if successful.
171
+ if method.is_a?(Qrack::Protocol09::Connection::Tune)
172
+ send_frame(Qrack::Protocol09::Connection::TuneOk.new(:channel_max => @channel_max, :frame_max => @frame_max, :heartbeat => @heartbeat))
173
+ end
236
174
 
237
- =end
175
+ send_frame(Qrack::Protocol09::Connection::Open.new(:virtual_host => @vhost, :reserved_1 => 0, :reserved_2 => false))
238
176
 
239
- def qos(opts = {})
177
+ raise Bunny::ProtocolError, 'Cannot open connection' unless next_method.is_a?(Qrack::Protocol09::Connection::OpenOk)
178
+ end
240
179
 
241
- send_frame(
242
- Qrack::Protocol09::Basic::Qos.new({ :prefetch_size => 0, :prefetch_count => 1, :global => false }.merge(opts))
243
- )
180
+ # Requests a specific quality of service. The QoS can be specified for the current channel
181
+ # or for all channels on the connection. The particular properties and semantics of a QoS
182
+ # method always depend on the content class semantics. Though the QoS method could in principle
183
+ # apply to both peers, it is currently meaningful only for the server.
184
+ #
185
+ # @option opts [Integer] :prefetch_size (0)
186
+ # Size in number of octets. The client can request that messages be sent in advance
187
+ # so that when the client finishes processing a message, the following message is
188
+ # already held locally, rather than needing to be sent down the channel. refetching
189
+ # gives a performance improvement. This field specifies the prefetch window size
190
+ # in octets. The server will send a message in advance if it is equal to or smaller
191
+ # in size than the available prefetch size (and also falls into other prefetch limits).
192
+ # May be set to zero, meaning "no specific limit", although other prefetch limits may
193
+ # still apply. The prefetch-size is ignored if the no-ack option is set.
194
+ #
195
+ # @option opts [Integer] :prefetch_count (1)
196
+ # Number of messages to prefetch. Specifies a prefetch window in terms of whole messages.
197
+ # This field may be used in combination with the prefetch-size field; a message will only
198
+ # be sent in advance if both prefetch windows (and those at the channel and connection level)
199
+ # allow it. The prefetch-count is ignored if the no-ack option is set.
200
+ #
201
+ # @option opts [Boolean] :global (false)
202
+ # By default the QoS settings apply to the current channel only. If set to true,
203
+ # they are applied to the entire connection.
204
+ #
205
+ # @return [Symbol] @:qos_ok@ if successful.
206
+ def qos(opts = {})
207
+ send_frame(Qrack::Protocol09::Basic::Qos.new({ :prefetch_size => 0, :prefetch_count => 1, :global => false }.merge(opts)))
244
208
 
245
209
  method = next_method
246
-
247
- check_response(method, Qrack::Protocol09::Basic::QosOk, "Error specifying Quality of Service")
210
+
211
+ check_response(method, Qrack::Protocol09::Basic::QosOk, "Error specifying Quality of Service")
248
212
 
249
213
  # return confirmation
250
214
  :qos_ok
251
215
  end
252
216
 
253
- =begin rdoc
254
-
255
- === DESCRIPTION:
256
-
257
- Declares a queue to the broker/server. If the queue does not exist, a new one is created
258
- using the arguments passed in. If the queue already exists, a reference to it is created, provided
259
- that the arguments passed in do not conflict with the existing attributes of the queue. If an error
260
- occurs a _Bunny_::_ProtocolError_ is raised.
261
-
262
- ==== OPTIONS:
263
-
264
- * <tt>:passive => true or false (_default_)</tt> - If set to _true_, the server will not create
265
- the queue. The client can use this to check whether a queue exists without modifying the server
266
- state.
267
- * <tt>:durable => true or false (_default_)</tt> - If set to _true_ when creating a new queue, the
268
- queue will be marked as durable. Durable queues remain active when a server restarts. Non-durable
269
- queues (transient queues) are purged if/when a server restarts. Note that durable queues do not
270
- necessarily hold persistent messages, although it does not make sense to send persistent messages
271
- to a transient queue.
272
- * <tt>:exclusive => true or false (_default_)</tt> - If set to _true_, requests an exclusive queue.
273
- Exclusive queues may only be consumed from by the current connection. Setting the 'exclusive'
274
- flag always implies 'auto-delete'.
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
277
- or because its channel is closed. If there has never been a consumer on the queue, it is not
278
- deleted.
279
- * <tt>:nowait => true or false (_default_)</tt> - Ignored by Bunny, always _false_.
280
-
281
- ==== RETURNS:
282
-
283
- Queue
284
-
285
- =end
286
-
287
- def queue(name = nil, opts = {})
217
+ # Declares a queue to the broker/server. If the queue does not exist, a new one is created
218
+ # using the arguments passed in. If the queue already exists, a reference to it is created, provided
219
+ # that the arguments passed in do not conflict with the existing attributes of the queue. If an error
220
+ # occurs a {Bunny::ProtocolError} is raised.
221
+ #
222
+ # @option opts [Boolean] :passive (false)
223
+ # If set to @true@, the server will not create the queue. The client can use this to check
224
+ # whether a queue exists without modifying the server state.
225
+ #
226
+ # @option opts [Boolean] :durable (false)
227
+ # If set to @true@ when creating a new queue, the queue will be marked as durable.
228
+ # Durable queues remain active when a server restarts. Non-durable queues (transient ones)
229
+ # are purged if/when a server restarts. Note that durable queues do not necessarily hold
230
+ # persistent messages, although it does not make sense to send persistent messages
231
+ # to a transient queue.
232
+ #
233
+ # @option opts [Boolean] :exclusive (false)
234
+ # If set to @true@, requests an exclusive queue. Exclusive queues may only be consumed
235
+ # from by the current connection. Setting the 'exclusive' flag always implies 'auto-delete'.
236
+ #
237
+ # @option opts [Boolean] :auto_delete (false)
238
+ # If set to @true@, the queue is deleted when all consumers have finished using it.
239
+ # Last consumer can be cancelled either explicitly or because its channel is closed.
240
+ # If there has never been a consumer on the queue, it is not deleted.
241
+ #
242
+ # @option opts [Boolean] :nowait (false)
243
+ # Ignored by Bunny, always @false@.
244
+ #
245
+ # @return [Bunny::Queue09]
246
+ def queue(name = nil, opts = {})
288
247
  if name.is_a?(Hash)
289
248
  opts = name
290
249
  name = nil
@@ -292,32 +251,20 @@ Queue
292
251
 
293
252
  # Queue is responsible for placing itself in the list of queues
294
253
  queues[name] || Bunny::Queue09.new(self, name, opts)
295
- end
296
-
297
- =begin rdoc
298
-
299
- === DESCRIPTION:
300
-
301
- Asks the broker to redeliver all unacknowledged messages on a specified channel. Zero or
302
- more messages may be redelivered.
303
-
304
- ==== Options:
305
-
306
- * <tt>:requeue => true or false (_default_)</tt> - If set to _false_, the message will be
307
- redelivered to the original recipient. If set to _true_, the server will attempt to requeue
308
- the message, potentially then delivering it to an alternative subscriber.
309
-
310
- =end
311
-
312
- def recover(opts = {})
254
+ end
313
255
 
314
- send_frame(
315
- Qrack::Protocol09::Basic::Recover.new({ :requeue => false }.merge(opts))
316
- )
256
+ # Asks the broker to redeliver all unacknowledged messages on a specified channel. Zero or
257
+ # more messages may be redelivered.
258
+ #
259
+ # @option opts [Boolean] :requeue (false)
260
+ # If set to @false@, the message will be redelivered to the original recipient.
261
+ # If set to @true@, the server will attempt to requeue the message, potentially
262
+ # then delivering it to an alternative subscriber.
263
+ def recover(opts = {})
264
+ send_frame(Qrack::Protocol09::Basic::Recover.new({ :requeue => false }.merge(opts)))
265
+ end
317
266
 
318
- end
319
-
320
- def send_frame(*args)
267
+ def send_frame(*args)
321
268
  args.each do |data|
322
269
  data = data.to_frame(channel.number) unless data.is_a?(Qrack::Transport09::Frame)
323
270
  data.channel = channel.number
@@ -325,132 +272,99 @@ the message, potentially then delivering it to an alternative subscriber.
325
272
  @logger.info("send") { data } if @logging
326
273
  write(data.to_s)
327
274
 
328
- # Monitor client activity for heartbeat purposes
329
- @message_out = true
275
+ # Monitor client activity for heartbeat purposes
276
+ @message_out = true
330
277
  end
331
278
 
332
279
  nil
333
280
  end
334
-
335
- def send_heartbeat
336
- # Create a new heartbeat frame
337
- hb = Qrack::Transport09::Heartbeat.new('')
338
- # Channel 0 must be used
339
- switch_channel(0) if @channel.number > 0
340
- # Send the heartbeat to server
341
- send_frame(hb)
342
- end
343
-
344
- =begin rdoc
345
-
346
- === DESCRIPTION:
347
-
348
- Opens a communication channel and starts a connection. If an error occurs, a
349
- _Bunny_::_ProtocolError_ is raised. If successful, _Client_._status_ is set to <tt>:connected</tt>.
350
-
351
- ==== RETURNS:
352
-
353
- <tt>:connected</tt> if successful.
354
-
355
- =end
356
-
357
- def start_session
358
- @connecting = true
359
-
360
- # Create/get socket
361
- socket
362
-
363
- # Initiate connection
364
- init_connection
365
-
366
- # Open connection
367
- open_connection
368
-
369
- # Open another channel because channel zero is used for specific purposes
370
- c = create_channel()
371
- c.open
372
-
373
- @connecting = false
374
-
375
- # return status
376
- @status = :connected
377
- end
378
281
 
379
- alias start start_session
380
-
381
- =begin rdoc
282
+ def send_heartbeat
283
+ # Create a new heartbeat frame
284
+ hb = Qrack::Transport09::Heartbeat.new('')
285
+ # Channel 0 must be used
286
+ switch_channel(0) if @channel.number > 0
287
+ # Send the heartbeat to server
288
+ send_frame(hb)
289
+ end
382
290
 
383
- === DESCRIPTION:
384
- This method commits all messages published and acknowledged in
385
- the current transaction. A new transaction starts immediately
386
- after a commit.
291
+ # Opens a communication channel and starts a connection. If an error occurs, a
292
+ # {Bunny::ProtocolError} is raised. If successful, {Client.status} is set to @:connected@.
293
+ #
294
+ # @return [Symbol] @:connected@ if successful.
295
+ def start_session
296
+ @connecting = true
387
297
 
388
- ==== RETURNS:
298
+ # Create/get socket
299
+ socket
389
300
 
390
- <tt>:commit_ok</tt> if successful.
301
+ # Initiate connection
302
+ init_connection
391
303
 
392
- =end
304
+ # Open connection
305
+ open_connection
393
306
 
394
- def tx_commit
395
- send_frame(Qrack::Protocol09::Tx::Commit.new())
307
+ # Open another channel because channel zero is used for specific purposes
308
+ c = create_channel()
309
+ c.open
396
310
 
397
- method = next_method
398
-
399
- check_response(method, Qrack::Protocol09::Tx::CommitOk, "Error commiting transaction")
311
+ @connecting = false
400
312
 
401
- # return confirmation
402
- :commit_ok
403
- end
404
-
405
- =begin rdoc
313
+ # return status
314
+ @status = :connected
315
+ end
406
316
 
407
- === DESCRIPTION:
408
- This method abandons all messages published and acknowledged in
409
- the current transaction. A new transaction starts immediately
410
- after a rollback.
317
+ alias start start_session
411
318
 
412
- ==== RETURNS:
319
+ # This method commits all messages published and acknowledged in
320
+ # the current transaction. A new transaction starts immediately
321
+ # after a commit.
322
+ #
323
+ # @return [Symbol] @:commit_ok@ if successful.
324
+ def tx_commit
325
+ send_frame(Qrack::Protocol09::Tx::Commit.new())
413
326
 
414
- <tt>:rollback_ok</tt> if successful.
327
+ method = next_method
415
328
 
416
- =end
329
+ check_response(method, Qrack::Protocol09::Tx::CommitOk, "Error commiting transaction")
417
330
 
418
- def tx_rollback
419
- send_frame(Qrack::Protocol09::Tx::Rollback.new())
331
+ # return confirmation
332
+ :commit_ok
333
+ end
420
334
 
421
- method = next_method
422
-
423
- check_response(method, Qrack::Protocol09::Tx::RollbackOk, "Error rolling back transaction")
335
+ # This method abandons all messages published and acknowledged in
336
+ # the current transaction. A new transaction starts immediately
337
+ # after a rollback.
338
+ #
339
+ # @return [Symbol] @:rollback_ok@ if successful.
340
+ def tx_rollback
341
+ send_frame(Qrack::Protocol09::Tx::Rollback.new())
424
342
 
425
- # return confirmation
426
- :rollback_ok
427
- end
428
-
429
- =begin rdoc
343
+ method = next_method
430
344
 
431
- === DESCRIPTION:
432
- This method sets the channel to use standard transactions. The
433
- client must use this method at least once on a channel before
434
- using the Commit or Rollback methods.
345
+ check_response(method, Qrack::Protocol09::Tx::RollbackOk, "Error rolling back transaction")
435
346
 
436
- ==== RETURNS:
347
+ # return confirmation
348
+ :rollback_ok
349
+ end
437
350
 
438
- <tt>:select_ok</tt> if successful.
351
+ # This method sets the channel to use standard transactions. The
352
+ # client must use this method at least once on a channel before
353
+ # using the Commit or Rollback methods.
354
+ #
355
+ # @return [Symbol] @:select_ok@ if successful.
356
+ def tx_select
357
+ send_frame(Qrack::Protocol09::Tx::Select.new())
439
358
 
440
- =end
359
+ method = next_method
441
360
 
442
- def tx_select
443
- send_frame(Qrack::Protocol09::Tx::Select.new())
444
-
445
- method = next_method
446
-
447
- check_response(method, Qrack::Protocol::Tx::SelectOk, "Error initiating transactions for current channel")
361
+ check_response(method, Qrack::Protocol::Tx::SelectOk, "Error initiating transactions for current channel")
448
362
 
449
- # return confirmation
450
- :select_ok
451
- end
363
+ # return confirmation
364
+ :select_ok
365
+ end
452
366
 
453
- private
367
+ private
454
368
 
455
369
  def buffer
456
370
  @buffer ||= Qrack::Transport09::Buffer.new(self)