bunny 0.6.3.rc2 → 0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/.rspec +3 -0
- data/.travis.yml +15 -0
- data/.yardopts +9 -0
- data/CHANGELOG +3 -0
- data/Gemfile +39 -0
- data/Gemfile.lock +34 -0
- data/LICENSE +5 -4
- data/README.textile +54 -0
- data/Rakefile +15 -13
- data/bunny.gemspec +42 -61
- data/examples/simple_08.rb +4 -2
- data/examples/simple_09.rb +4 -2
- data/examples/simple_ack_08.rb +3 -1
- data/examples/simple_ack_09.rb +3 -1
- data/examples/simple_consumer_08.rb +4 -2
- data/examples/simple_consumer_09.rb +4 -2
- data/examples/simple_fanout_08.rb +3 -1
- data/examples/simple_fanout_09.rb +3 -1
- data/examples/simple_headers_08.rb +5 -3
- data/examples/simple_headers_09.rb +5 -3
- data/examples/simple_publisher_08.rb +3 -1
- data/examples/simple_publisher_09.rb +3 -1
- data/examples/simple_topic_08.rb +5 -3
- data/examples/simple_topic_09.rb +5 -3
- data/ext/amqp-0.8.json +616 -0
- data/ext/amqp-0.9.1.json +388 -0
- data/ext/config.yml +4 -0
- data/ext/qparser.rb +463 -0
- data/lib/bunny.rb +88 -66
- data/lib/bunny/channel08.rb +38 -38
- data/lib/bunny/channel09.rb +37 -37
- data/lib/bunny/client08.rb +184 -206
- data/lib/bunny/client09.rb +277 -363
- data/lib/bunny/consumer.rb +35 -0
- data/lib/bunny/exchange08.rb +37 -41
- data/lib/bunny/exchange09.rb +106 -124
- data/lib/bunny/queue08.rb +216 -202
- data/lib/bunny/queue09.rb +256 -326
- data/lib/bunny/subscription08.rb +30 -29
- data/lib/bunny/subscription09.rb +84 -83
- data/lib/bunny/version.rb +5 -0
- data/lib/qrack/amq-client-url.rb +165 -0
- data/lib/qrack/channel.rb +19 -17
- data/lib/qrack/client.rb +152 -151
- data/lib/qrack/errors.rb +5 -0
- data/lib/qrack/protocol/protocol08.rb +132 -130
- data/lib/qrack/protocol/protocol09.rb +133 -131
- data/lib/qrack/protocol/spec08.rb +2 -0
- data/lib/qrack/protocol/spec09.rb +2 -0
- data/lib/qrack/qrack08.rb +7 -10
- data/lib/qrack/qrack09.rb +7 -10
- data/lib/qrack/queue.rb +27 -40
- data/lib/qrack/subscription.rb +102 -101
- data/lib/qrack/transport/buffer08.rb +266 -264
- data/lib/qrack/transport/buffer09.rb +268 -264
- data/lib/qrack/transport/frame08.rb +13 -11
- data/lib/qrack/transport/frame09.rb +9 -7
- data/spec/spec_08/bunny_spec.rb +48 -45
- data/spec/spec_08/connection_spec.rb +10 -7
- data/spec/spec_08/exchange_spec.rb +145 -143
- data/spec/spec_08/queue_spec.rb +161 -161
- data/spec/spec_09/bunny_spec.rb +46 -44
- data/spec/spec_09/connection_spec.rb +15 -8
- data/spec/spec_09/exchange_spec.rb +147 -145
- data/spec/spec_09/queue_spec.rb +182 -184
- metadata +60 -41
- data/README.rdoc +0 -66
data/lib/bunny/client09.rb
CHANGED
@@ -1,290 +1,249 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
=begin rdoc
|
4
|
-
|
5
|
-
=== DESCRIPTION:
|
1
|
+
# encoding: utf-8
|
6
2
|
|
7
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
=
|
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
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
-
|
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
|
-
|
64
|
-
|
48
|
+
when received_method.is_a?(Qrack::Protocol09::Channel::Close)
|
49
|
+
# Clean up the channel
|
50
|
+
channel.active = false
|
65
51
|
|
66
|
-
|
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
|
-
|
71
|
-
|
54
|
+
when !received_method.is_a?(expected_method)
|
55
|
+
raise err_class, err_msg
|
72
56
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
:response_ok
|
78
|
-
end
|
79
|
-
end
|
57
|
+
else
|
58
|
+
:response_ok
|
59
|
+
end
|
60
|
+
end
|
80
61
|
|
81
|
-
|
82
|
-
|
62
|
+
def close_connection
|
63
|
+
# Set client channel to zero
|
83
64
|
switch_channel(0)
|
84
65
|
|
85
|
-
|
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
|
-
|
70
|
+
check_response(method, Qrack::Protocol09::Connection::CloseOk, "Error closing connection")
|
113
71
|
|
114
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
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
|
-
|
140
|
-
|
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
|
-
|
180
|
-
|
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
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
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
|
-
|
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::
|
205
|
-
end
|
137
|
+
raise Bunny::ConnectionError, 'No connection to server' if (frame.nil? and !connecting?)
|
206
138
|
|
207
|
-
|
139
|
+
# Monitor server activity and discard heartbeats
|
140
|
+
@message_in = true
|
208
141
|
|
209
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
219
|
-
|
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
|
-
|
169
|
+
method = frame.payload
|
234
170
|
|
235
|
-
|
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
|
-
|
175
|
+
send_frame(Qrack::Protocol09::Connection::Open.new(:virtual_host => @vhost, :reserved_1 => 0, :reserved_2 => false))
|
238
176
|
|
239
|
-
|
177
|
+
raise Bunny::ProtocolError, 'Cannot open connection' unless next_method.is_a?(Qrack::Protocol09::Connection::OpenOk)
|
178
|
+
end
|
240
179
|
|
241
|
-
|
242
|
-
|
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
|
-
|
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
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
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
|
-
|
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
|
-
|
315
|
-
|
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
|
-
|
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
|
-
|
329
|
-
|
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
|
-
|
380
|
-
|
381
|
-
=
|
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
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
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
|
-
|
298
|
+
# Create/get socket
|
299
|
+
socket
|
389
300
|
|
390
|
-
|
301
|
+
# Initiate connection
|
302
|
+
init_connection
|
391
303
|
|
392
|
-
|
304
|
+
# Open connection
|
305
|
+
open_connection
|
393
306
|
|
394
|
-
|
395
|
-
|
307
|
+
# Open another channel because channel zero is used for specific purposes
|
308
|
+
c = create_channel()
|
309
|
+
c.open
|
396
310
|
|
397
|
-
|
398
|
-
|
399
|
-
check_response(method, Qrack::Protocol09::Tx::CommitOk, "Error commiting transaction")
|
311
|
+
@connecting = false
|
400
312
|
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
=begin rdoc
|
313
|
+
# return status
|
314
|
+
@status = :connected
|
315
|
+
end
|
406
316
|
|
407
|
-
|
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
|
-
|
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
|
-
|
327
|
+
method = next_method
|
415
328
|
|
416
|
-
|
329
|
+
check_response(method, Qrack::Protocol09::Tx::CommitOk, "Error commiting transaction")
|
417
330
|
|
418
|
-
|
419
|
-
|
331
|
+
# return confirmation
|
332
|
+
:commit_ok
|
333
|
+
end
|
420
334
|
|
421
|
-
|
422
|
-
|
423
|
-
|
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
|
-
|
426
|
-
:rollback_ok
|
427
|
-
end
|
428
|
-
|
429
|
-
=begin rdoc
|
343
|
+
method = next_method
|
430
344
|
|
431
|
-
|
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
|
-
|
347
|
+
# return confirmation
|
348
|
+
:rollback_ok
|
349
|
+
end
|
437
350
|
|
438
|
-
|
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
|
-
=
|
359
|
+
method = next_method
|
441
360
|
|
442
|
-
|
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
|
-
|
450
|
-
|
451
|
-
|
363
|
+
# return confirmation
|
364
|
+
:select_ok
|
365
|
+
end
|
452
366
|
|
453
|
-
|
367
|
+
private
|
454
368
|
|
455
369
|
def buffer
|
456
370
|
@buffer ||= Qrack::Transport09::Buffer.new(self)
|