bunny 0.7.12 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -2
- data/.travis.yml +7 -16
- data/CHANGELOG +3 -21
- data/Gemfile +2 -4
- data/README.textile +31 -9
- data/Rakefile +3 -3
- data/bunny.gemspec +6 -3
- data/examples/{simple_08.rb → simple.rb} +1 -1
- data/examples/{simple_ack_08.rb → simple_ack.rb} +1 -1
- data/examples/{simple_consumer_08.rb → simple_consumer.rb} +4 -4
- data/examples/{simple_fanout_08.rb → simple_fanout.rb} +1 -1
- data/examples/{simple_headers_08.rb → simple_headers.rb} +2 -2
- data/examples/{simple_publisher_09.rb → simple_publisher.rb} +1 -1
- data/examples/{simple_topic_09.rb → simple_topic.rb} +2 -2
- data/ext/amqp-0.9.1.json +1 -0
- data/ext/config.yml +3 -3
- data/ext/qparser.rb +9 -52
- data/lib/bunny.rb +15 -33
- data/lib/bunny/{channel08.rb → channel.rb} +0 -0
- data/lib/bunny/{client09.rb → client.rb} +34 -46
- data/lib/bunny/{exchange09.rb → exchange.rb} +16 -15
- data/lib/bunny/{queue09.rb → queue.rb} +26 -23
- data/lib/bunny/{subscription09.rb → subscription.rb} +11 -6
- data/lib/bunny/version.rb +1 -1
- data/lib/qrack/client.rb +30 -21
- data/lib/qrack/protocol/{protocol08.rb → protocol.rb} +2 -1
- data/lib/qrack/protocol/{spec09.rb → spec.rb} +8 -7
- data/lib/qrack/{qrack08.rb → qrack.rb} +4 -4
- data/lib/qrack/subscription.rb +58 -9
- data/lib/qrack/transport/{buffer08.rb → buffer.rb} +8 -0
- data/lib/qrack/transport/{frame08.rb → frame.rb} +7 -22
- data/spec/spec_09/bunny_spec.rb +10 -8
- data/spec/spec_09/connection_spec.rb +8 -3
- data/spec/spec_09/exchange_spec.rb +22 -19
- data/spec/spec_09/queue_spec.rb +32 -18
- metadata +69 -76
- checksums.yaml +0 -7
- data/examples/simple_09.rb +0 -32
- data/examples/simple_ack_09.rb +0 -35
- data/examples/simple_consumer_09.rb +0 -55
- data/examples/simple_fanout_09.rb +0 -41
- data/examples/simple_headers_09.rb +0 -42
- data/examples/simple_publisher_08.rb +0 -29
- data/examples/simple_topic_08.rb +0 -61
- data/ext/amqp-0.8.json +0 -616
- data/lib/bunny/channel09.rb +0 -39
- data/lib/bunny/client08.rb +0 -480
- data/lib/bunny/exchange08.rb +0 -177
- data/lib/bunny/queue08.rb +0 -403
- data/lib/bunny/subscription08.rb +0 -87
- data/lib/qrack/protocol/protocol09.rb +0 -135
- data/lib/qrack/protocol/spec08.rb +0 -828
- data/lib/qrack/qrack09.rb +0 -20
- data/lib/qrack/transport/buffer09.rb +0 -305
- data/lib/qrack/transport/frame09.rb +0 -97
- data/spec/spec_08/bunny_spec.rb +0 -75
- data/spec/spec_08/connection_spec.rb +0 -24
- data/spec/spec_08/exchange_spec.rb +0 -170
- data/spec/spec_08/queue_spec.rb +0 -239
data/lib/bunny.rb
CHANGED
@@ -34,25 +34,21 @@ module Bunny
|
|
34
34
|
# Instantiates new Bunny::Client
|
35
35
|
|
36
36
|
def self.new(connection_string_or_opts = Hash.new, opts = Hash.new)
|
37
|
-
# Set up Bunny
|
37
|
+
# Set up Bunny
|
38
38
|
if connection_string_or_opts.respond_to?(:keys) && opts.empty?
|
39
39
|
opts = connection_string_or_opts
|
40
40
|
end
|
41
41
|
|
42
|
-
spec_version = opts[:spec] || '08'
|
43
|
-
|
44
42
|
# Return client
|
45
|
-
setup(
|
43
|
+
setup(connection_string_or_opts, opts)
|
46
44
|
end
|
47
45
|
|
48
|
-
# Runs a code block using a
|
49
|
-
|
50
|
-
def self.run(opts = {}, &block)
|
46
|
+
# Runs a code block using a Bunny connection
|
47
|
+
def self.run(connection_string_or_opts = {}, opts = {}, &block)
|
51
48
|
raise ArgumentError, 'Bunny#run requires a block' unless block
|
52
49
|
|
53
|
-
# Set up Bunny
|
54
|
-
|
55
|
-
client = setup(spec_version, opts)
|
50
|
+
# Set up Bunny
|
51
|
+
client = setup(connection_string_or_opts, opts)
|
56
52
|
|
57
53
|
begin
|
58
54
|
client.start
|
@@ -78,32 +74,18 @@ module Bunny
|
|
78
74
|
|
79
75
|
private
|
80
76
|
|
81
|
-
def self.setup(
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
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
|
77
|
+
def self.setup(*args)
|
78
|
+
# AMQP 0-9-1 specification
|
79
|
+
require 'qrack/qrack'
|
80
|
+
require 'bunny/client'
|
81
|
+
require 'bunny/exchange'
|
82
|
+
require 'bunny/queue'
|
83
|
+
require 'bunny/channel'
|
84
|
+
require 'bunny/subscription'
|
103
85
|
|
104
86
|
include Qrack
|
105
87
|
|
106
|
-
client
|
88
|
+
client = Bunny::Client.new(*args)
|
107
89
|
end
|
108
90
|
|
109
91
|
end
|
File without changes
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Bunny
|
4
4
|
|
5
5
|
# The Client class provides the major Bunny API methods.
|
6
|
-
class
|
6
|
+
class Client < Qrack::Client
|
7
7
|
|
8
8
|
# Sets up a Bunny::Client object ready for connection to a broker.
|
9
9
|
# {Client.status} is set to @:not_connected@.
|
@@ -32,20 +32,20 @@ module Bunny
|
|
32
32
|
# Number of seconds before {Qrack::ConnectionTimeout} is raised.@
|
33
33
|
def initialize(connection_string_or_opts = Hash.new, opts = Hash.new)
|
34
34
|
super
|
35
|
-
@spec = '0-9-1'
|
36
|
-
@port = self.__opts__[:port] || (self.__opts__[:ssl] ? Qrack::Protocol09::SSL_PORT : Qrack::Protocol09::PORT)
|
37
35
|
end
|
38
36
|
|
39
37
|
# Checks response from AMQP methods and takes appropriate action
|
40
38
|
def check_response(received_method, expected_method, err_msg, err_class = Bunny::ProtocolError)
|
39
|
+
@last_method = received_method
|
40
|
+
|
41
41
|
case
|
42
|
-
when received_method.is_a?(Qrack::
|
42
|
+
when received_method.is_a?(Qrack::Protocol::Connection::Close)
|
43
43
|
# Clean up the socket
|
44
44
|
close_socket
|
45
45
|
|
46
46
|
raise Bunny::ForcedConnectionCloseError, "Error Reply Code: #{received_method.reply_code}\nError Reply Text: #{received_method.reply_text}"
|
47
47
|
|
48
|
-
when received_method.is_a?(Qrack::
|
48
|
+
when received_method.is_a?(Qrack::Protocol::Channel::Close)
|
49
49
|
# Clean up the channel
|
50
50
|
channel.active = false
|
51
51
|
|
@@ -63,11 +63,11 @@ module Bunny
|
|
63
63
|
# Set client channel to zero
|
64
64
|
switch_channel(0)
|
65
65
|
|
66
|
-
send_frame(Qrack::
|
66
|
+
send_frame(Qrack::Protocol::Connection::Close.new(:reply_code => 200, :reply_text => 'Goodbye', :class_id => 0, :method_id => 0))
|
67
67
|
|
68
68
|
method = next_method
|
69
69
|
|
70
|
-
check_response(method, Qrack::
|
70
|
+
check_response(method, Qrack::Protocol::Connection::CloseOk, "Error closing connection")
|
71
71
|
|
72
72
|
end
|
73
73
|
|
@@ -76,7 +76,7 @@ module Bunny
|
|
76
76
|
return c if (!c.open? and c.number != 0)
|
77
77
|
end
|
78
78
|
# If no channel to re-use instantiate new one
|
79
|
-
Bunny::
|
79
|
+
Bunny::Channel.new(self)
|
80
80
|
end
|
81
81
|
|
82
82
|
# Declares an exchange to the broker/server. If the exchange does not exist, a new one is created
|
@@ -103,17 +103,17 @@ module Bunny
|
|
103
103
|
# @option opts [Boolean] :nowait (false)
|
104
104
|
# Ignored by Bunny, always @false@.
|
105
105
|
#
|
106
|
-
# @return [Bunny::
|
106
|
+
# @return [Bunny::Exchange]
|
107
107
|
def exchange(name, opts = {})
|
108
|
-
exchanges[name] || Bunny::
|
108
|
+
exchanges[name] || Bunny::Exchange.new(self, name, opts)
|
109
109
|
end
|
110
110
|
|
111
111
|
def init_connection
|
112
|
-
write(Qrack::
|
113
|
-
write([0, Qrack::
|
112
|
+
write(Qrack::Protocol::HEADER)
|
113
|
+
write([0, Qrack::Protocol::VERSION_MAJOR, Qrack::Protocol::VERSION_MINOR, Qrack::Protocol::REVISION].pack('C4'))
|
114
114
|
|
115
115
|
frame = next_frame
|
116
|
-
if frame.nil? or !frame.payload.is_a?(Qrack::
|
116
|
+
if frame.nil? or !frame.payload.is_a?(Qrack::Protocol::Connection::Start)
|
117
117
|
raise Bunny::ProtocolError, 'Connection initiation failed'
|
118
118
|
end
|
119
119
|
end
|
@@ -124,12 +124,8 @@ module Bunny
|
|
124
124
|
case
|
125
125
|
when channel.frame_buffer.size > 0
|
126
126
|
frame = channel.frame_buffer.shift
|
127
|
-
when (timeout = opts[:timeout]) && timeout > 0
|
128
|
-
Bunny::Timer::timeout(timeout, Qrack::FrameTimeout) do
|
129
|
-
frame = Qrack::Transport09::Frame.parse(buffer)
|
130
|
-
end
|
131
127
|
else
|
132
|
-
frame = Qrack::
|
128
|
+
frame = Qrack::Transport::Frame.parse(buffer, opts)
|
133
129
|
end
|
134
130
|
|
135
131
|
@logger.info("received") { frame } if @logging
|
@@ -140,7 +136,7 @@ module Bunny
|
|
140
136
|
@message_in = true
|
141
137
|
|
142
138
|
case
|
143
|
-
when frame.is_a?(Qrack::
|
139
|
+
when frame.is_a?(Qrack::Transport::Heartbeat)
|
144
140
|
next_frame(opts)
|
145
141
|
when frame.nil?
|
146
142
|
frame
|
@@ -161,22 +157,20 @@ module Bunny
|
|
161
157
|
:response => "\0" + @user + "\0" + @pass,
|
162
158
|
:locale => 'en_US'
|
163
159
|
}
|
164
|
-
send_frame(Qrack::
|
160
|
+
send_frame(Qrack::Protocol::Connection::StartOk.new(start_opts))
|
165
161
|
|
166
162
|
frame = next_frame
|
167
163
|
raise Bunny::ProtocolError, "Connection failed - user: #{@user}" if frame.nil?
|
168
164
|
|
169
165
|
method = frame.payload
|
170
166
|
|
171
|
-
if method.is_a?(Qrack::
|
172
|
-
@
|
173
|
-
@channel_max = method.channel_max if method.channel_max > 0 && method.channel_max < @channel_max
|
174
|
-
send_frame(Qrack::Protocol09::Connection::TuneOk.new(:channel_max => @channel_max, :frame_max => @frame_max, :heartbeat => @heartbeat))
|
167
|
+
if method.is_a?(Qrack::Protocol::Connection::Tune)
|
168
|
+
send_frame(Qrack::Protocol::Connection::TuneOk.new(:channel_max => @channel_max, :frame_max => @frame_max, :heartbeat => @heartbeat))
|
175
169
|
end
|
176
170
|
|
177
|
-
send_frame(Qrack::
|
171
|
+
send_frame(Qrack::Protocol::Connection::Open.new(:virtual_host => @vhost, :reserved_1 => 0, :reserved_2 => false))
|
178
172
|
|
179
|
-
raise Bunny::ProtocolError, 'Cannot open connection' unless next_method.is_a?(Qrack::
|
173
|
+
raise Bunny::ProtocolError, 'Cannot open connection' unless next_method.is_a?(Qrack::Protocol::Connection::OpenOk)
|
180
174
|
end
|
181
175
|
|
182
176
|
# Requests a specific quality of service. The QoS can be specified for the current channel
|
@@ -206,11 +200,11 @@ module Bunny
|
|
206
200
|
#
|
207
201
|
# @return [Symbol] @:qos_ok@ if successful.
|
208
202
|
def qos(opts = {})
|
209
|
-
send_frame(Qrack::
|
203
|
+
send_frame(Qrack::Protocol::Basic::Qos.new({ :prefetch_size => 0, :prefetch_count => 1, :global => false }.merge(opts)))
|
210
204
|
|
211
205
|
method = next_method
|
212
206
|
|
213
|
-
check_response(method, Qrack::
|
207
|
+
check_response(method, Qrack::Protocol::Basic::QosOk, "Error specifying Quality of Service")
|
214
208
|
|
215
209
|
# return confirmation
|
216
210
|
:qos_ok
|
@@ -244,7 +238,7 @@ module Bunny
|
|
244
238
|
# @option opts [Boolean] :nowait (false)
|
245
239
|
# Ignored by Bunny, always @false@.
|
246
240
|
#
|
247
|
-
# @return [Bunny::
|
241
|
+
# @return [Bunny::Queue]
|
248
242
|
def queue(name = nil, opts = {})
|
249
243
|
if name.is_a?(Hash)
|
250
244
|
opts = name
|
@@ -252,7 +246,7 @@ module Bunny
|
|
252
246
|
end
|
253
247
|
|
254
248
|
# Queue is responsible for placing itself in the list of queues
|
255
|
-
queues[name] || Bunny::
|
249
|
+
queues[name] || Bunny::Queue.new(self, name, opts)
|
256
250
|
end
|
257
251
|
|
258
252
|
# Asks the broker to redeliver all unacknowledged messages on a specified channel. Zero or
|
@@ -263,12 +257,12 @@ module Bunny
|
|
263
257
|
# If set to @true@, the server will attempt to requeue the message, potentially
|
264
258
|
# then delivering it to an alternative subscriber.
|
265
259
|
def recover(opts = {})
|
266
|
-
send_frame(Qrack::
|
260
|
+
send_frame(Qrack::Protocol::Basic::Recover.new({ :requeue => false }.merge(opts)))
|
267
261
|
end
|
268
262
|
|
269
263
|
def send_frame(*args)
|
270
264
|
args.each do |data|
|
271
|
-
data = data.to_frame(channel.number) unless data.is_a?(Qrack::
|
265
|
+
data = data.to_frame(channel.number) unless data.is_a?(Qrack::Transport::Frame)
|
272
266
|
data.channel = channel.number
|
273
267
|
|
274
268
|
@logger.info("send") { data } if @logging
|
@@ -283,7 +277,7 @@ module Bunny
|
|
283
277
|
|
284
278
|
def send_heartbeat
|
285
279
|
# Create a new heartbeat frame
|
286
|
-
hb = Qrack::
|
280
|
+
hb = Qrack::Transport::Heartbeat.new('')
|
287
281
|
# Channel 0 must be used
|
288
282
|
switch_channel(0) if @channel.number > 0
|
289
283
|
# Send the heartbeat to server
|
@@ -324,11 +318,11 @@ module Bunny
|
|
324
318
|
#
|
325
319
|
# @return [Symbol] @:commit_ok@ if successful.
|
326
320
|
def tx_commit
|
327
|
-
send_frame(Qrack::
|
321
|
+
send_frame(Qrack::Protocol::Tx::Commit.new())
|
328
322
|
|
329
323
|
method = next_method
|
330
324
|
|
331
|
-
check_response(method, Qrack::
|
325
|
+
check_response(method, Qrack::Protocol::Tx::CommitOk, "Error commiting transaction")
|
332
326
|
|
333
327
|
# return confirmation
|
334
328
|
:commit_ok
|
@@ -340,11 +334,11 @@ module Bunny
|
|
340
334
|
#
|
341
335
|
# @return [Symbol] @:rollback_ok@ if successful.
|
342
336
|
def tx_rollback
|
343
|
-
send_frame(Qrack::
|
337
|
+
send_frame(Qrack::Protocol::Tx::Rollback.new())
|
344
338
|
|
345
339
|
method = next_method
|
346
340
|
|
347
|
-
check_response(method, Qrack::
|
341
|
+
check_response(method, Qrack::Protocol::Tx::RollbackOk, "Error rolling back transaction")
|
348
342
|
|
349
343
|
# return confirmation
|
350
344
|
:rollback_ok
|
@@ -356,26 +350,20 @@ module Bunny
|
|
356
350
|
#
|
357
351
|
# @return [Symbol] @:select_ok@ if successful.
|
358
352
|
def tx_select
|
359
|
-
send_frame(Qrack::
|
353
|
+
send_frame(Qrack::Protocol::Tx::Select.new())
|
360
354
|
|
361
355
|
method = next_method
|
362
356
|
|
363
|
-
check_response(method, Qrack::
|
357
|
+
check_response(method, Qrack::Protocol::Tx::SelectOk, "Error initiating transactions for current channel")
|
364
358
|
|
365
359
|
# return confirmation
|
366
360
|
:select_ok
|
367
361
|
end
|
368
362
|
|
369
|
-
protected
|
370
|
-
|
371
|
-
def check_returned_message(method)
|
372
|
-
check_response(method, Qrack::Protocol09::Basic::Return, "Expected a returned message")
|
373
|
-
end
|
374
|
-
|
375
363
|
private
|
376
364
|
|
377
365
|
def buffer
|
378
|
-
@buffer ||= Qrack::
|
366
|
+
@buffer ||= Qrack::Transport::Buffer.new(self)
|
379
367
|
end
|
380
368
|
|
381
369
|
end
|
@@ -24,7 +24,7 @@ module Bunny
|
|
24
24
|
# If you want more information about exchanges, please consult the documentation for your
|
25
25
|
# target broker/server or visit the "AMQP website":http://www.amqp.org to find the version of the
|
26
26
|
# specification that applies to your target broker/server.
|
27
|
-
class
|
27
|
+
class Exchange
|
28
28
|
|
29
29
|
attr_reader :client, :type, :name, :opts, :key
|
30
30
|
|
@@ -58,11 +58,11 @@ module Bunny
|
|
58
58
|
:deprecated_ticket => 0, :deprecated_auto_delete => false, :deprecated_internal => false
|
59
59
|
}.merge(opts)
|
60
60
|
|
61
|
-
client.send_frame(Qrack::
|
61
|
+
client.send_frame(Qrack::Protocol::Exchange::Declare.new(opts))
|
62
62
|
|
63
63
|
method = client.next_method
|
64
64
|
|
65
|
-
client.check_response(method, Qrack::
|
65
|
+
client.check_response(method, Qrack::Protocol::Exchange::DeclareOk, "Error declaring exchange #{name}: type = #{type}")
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -83,11 +83,11 @@ module Bunny
|
|
83
83
|
|
84
84
|
opts = { :exchange => name, :nowait => false, :deprecated_ticket => 0 }.merge(opts)
|
85
85
|
|
86
|
-
client.send_frame(Qrack::
|
86
|
+
client.send_frame(Qrack::Protocol::Exchange::Delete.new(opts))
|
87
87
|
|
88
88
|
method = client.next_method
|
89
89
|
|
90
|
-
client.check_response(method, Qrack::
|
90
|
+
client.check_response(method, Qrack::Protocol::Exchange::DeleteOk, "Error deleting exchange #{name}")
|
91
91
|
|
92
92
|
client.exchanges.delete(name)
|
93
93
|
|
@@ -128,34 +128,35 @@ module Bunny
|
|
128
128
|
opts = opts.dup
|
129
129
|
out = []
|
130
130
|
|
131
|
+
|
131
132
|
# Set up options
|
132
133
|
routing_key = opts.delete(:key) || key
|
133
134
|
mandatory = opts.delete(:mandatory)
|
134
135
|
immediate = opts.delete(:immediate)
|
135
136
|
delivery_mode = opts.delete(:persistent) ? 2 : 1
|
136
137
|
content_type = opts.delete(:content_type) || 'application/octet-stream'
|
138
|
+
reply_to = opts.delete(:reply_to)
|
139
|
+
correlation_id = opts.delete(:correlation_id)
|
140
|
+
user_id = opts.delete(:user_id)
|
137
141
|
|
138
|
-
out << Qrack::
|
142
|
+
out << Qrack::Protocol::Basic::Publish.new({ :exchange => name,
|
139
143
|
:routing_key => routing_key,
|
140
144
|
:mandatory => mandatory,
|
141
145
|
:immediate => immediate,
|
142
146
|
:deprecated_ticket => 0 })
|
143
147
|
data = data.to_s
|
144
|
-
out << Qrack::
|
145
|
-
Qrack::
|
148
|
+
out << Qrack::Protocol::Header.new(
|
149
|
+
Qrack::Protocol::Basic,
|
146
150
|
data.bytesize, {
|
147
151
|
:content_type => content_type,
|
148
152
|
:delivery_mode => delivery_mode,
|
153
|
+
:reply_to => reply_to,
|
154
|
+
:correlation_id => correlation_id,
|
155
|
+
:user_id => user_id,
|
149
156
|
:priority => 0
|
150
157
|
}.merge(opts)
|
151
158
|
)
|
152
|
-
|
153
|
-
limit = @client.frame_max - 8
|
154
|
-
i = 0
|
155
|
-
while i < data.bytesize
|
156
|
-
out << Qrack::Transport09::Body.new(data.byteslice(i, limit))
|
157
|
-
i += limit
|
158
|
-
end
|
159
|
+
out << Qrack::Transport::Body.new(data)
|
159
160
|
|
160
161
|
client.send_frame(*out)
|
161
162
|
end
|
@@ -4,7 +4,7 @@ module Bunny
|
|
4
4
|
|
5
5
|
# Queues store and forward messages. Queues can be configured in the server or created at runtime.
|
6
6
|
# Queues must be attached to at least one exchange in order to receive messages from publishers.
|
7
|
-
class
|
7
|
+
class Queue < Qrack::Queue
|
8
8
|
def initialize(client, name, opts = {})
|
9
9
|
# check connection to server
|
10
10
|
raise Bunny::ConnectionError, 'Not connected to server' if client.status == :not_connected
|
@@ -31,11 +31,11 @@ module Bunny
|
|
31
31
|
|
32
32
|
opts = { :queue => name || '', :nowait => false, :deprecated_ticket => 0 }.merge(opts)
|
33
33
|
|
34
|
-
client.send_frame(Qrack::
|
34
|
+
client.send_frame(Qrack::Protocol::Queue::Declare.new(opts))
|
35
35
|
|
36
36
|
method = client.next_method
|
37
37
|
|
38
|
-
client.check_response(method, Qrack::
|
38
|
+
client.check_response(method, Qrack::Protocol::Queue::DeclareOk, "Error declaring queue #{name}")
|
39
39
|
|
40
40
|
@name = method.queue
|
41
41
|
client.queues[@name] = self
|
@@ -54,7 +54,7 @@ module Bunny
|
|
54
54
|
# @private
|
55
55
|
def self.consumer_class
|
56
56
|
# Bunny::Consumer
|
57
|
-
Bunny::
|
57
|
+
Bunny::Subscription
|
58
58
|
end # self.consumer_class
|
59
59
|
|
60
60
|
# Acknowledges one or more messages delivered via the _Deliver_ or _Get_-_Ok_ methods. The client can
|
@@ -78,7 +78,7 @@ module Bunny
|
|
78
78
|
|
79
79
|
opts = {:delivery_tag => delivery_tag, :multiple => false}.merge(opts)
|
80
80
|
|
81
|
-
client.send_frame(Qrack::
|
81
|
+
client.send_frame(Qrack::Protocol::Basic::Ack.new(opts))
|
82
82
|
|
83
83
|
# reset delivery tag
|
84
84
|
self.delivery_tag = nil
|
@@ -111,11 +111,11 @@ module Bunny
|
|
111
111
|
:deprecated_ticket => 0
|
112
112
|
}.merge(opts)
|
113
113
|
|
114
|
-
client.send_frame(Qrack::
|
114
|
+
client.send_frame(Qrack::Protocol::Queue::Bind.new(opts))
|
115
115
|
|
116
116
|
method = client.next_method
|
117
117
|
|
118
|
-
client.check_response(method, Qrack::
|
118
|
+
client.check_response(method, Qrack::Protocol::Queue::BindOk, "Error binding queue: #{name} to exchange: #{exchange}")
|
119
119
|
|
120
120
|
# return message
|
121
121
|
:bind_ok
|
@@ -144,11 +144,11 @@ module Bunny
|
|
144
144
|
|
145
145
|
opts = { :queue => name, :nowait => false, :deprecated_ticket => 0 }.merge(opts)
|
146
146
|
|
147
|
-
client.send_frame(Qrack::
|
147
|
+
client.send_frame(Qrack::Protocol::Queue::Delete.new(opts))
|
148
148
|
|
149
149
|
method = client.next_method
|
150
150
|
|
151
|
-
client.check_response(method, Qrack::
|
151
|
+
client.check_response(method, Qrack::Protocol::Queue::DeleteOk, "Error deleting queue #{name}")
|
152
152
|
|
153
153
|
client.queues.delete(name)
|
154
154
|
|
@@ -174,13 +174,13 @@ module Bunny
|
|
174
174
|
:deprecated_ticket => 0
|
175
175
|
}.merge(opts)
|
176
176
|
|
177
|
-
client.send_frame(Qrack::
|
177
|
+
client.send_frame(Qrack::Protocol::Basic::Get.new(opts))
|
178
178
|
|
179
179
|
method = client.next_method
|
180
180
|
|
181
|
-
if method.is_a?(Qrack::
|
181
|
+
if method.is_a?(Qrack::Protocol::Basic::GetEmpty) then
|
182
182
|
queue_empty = true
|
183
|
-
elsif !method.is_a?(Qrack::
|
183
|
+
elsif !method.is_a?(Qrack::Protocol::Basic::GetOk)
|
184
184
|
raise Bunny::ProtocolError, "Error getting message from queue #{name}"
|
185
185
|
end
|
186
186
|
|
@@ -221,11 +221,11 @@ module Bunny
|
|
221
221
|
|
222
222
|
opts = { :queue => name, :nowait => false, :deprecated_ticket => 0 }.merge(opts)
|
223
223
|
|
224
|
-
client.send_frame(Qrack::
|
224
|
+
client.send_frame(Qrack::Protocol::Queue::Purge.new(opts))
|
225
225
|
|
226
226
|
method = client.next_method
|
227
227
|
|
228
|
-
client.check_response(method, Qrack::
|
228
|
+
client.check_response(method, Qrack::Protocol::Queue::PurgeOk, "Error purging queue #{name}")
|
229
229
|
|
230
230
|
# return confirmation
|
231
231
|
:purge_ok
|
@@ -234,7 +234,7 @@ module Bunny
|
|
234
234
|
# @return [Hash] Hash with keys @:message_count@ and @consumer_count@.
|
235
235
|
def status
|
236
236
|
opts = { :queue => name, :passive => true, :deprecated_ticket => 0 }
|
237
|
-
client.send_frame(Qrack::
|
237
|
+
client.send_frame(Qrack::Protocol::Queue::Declare.new(opts))
|
238
238
|
|
239
239
|
method = client.next_method
|
240
240
|
{:message_count => method.message_count, :consumer_count => method.consumer_count}
|
@@ -272,11 +272,11 @@ module Bunny
|
|
272
272
|
:deprecated_ticket => 0
|
273
273
|
}.merge(opts)
|
274
274
|
|
275
|
-
client.send_frame(Qrack::
|
275
|
+
client.send_frame(Qrack::Protocol::Queue::Unbind.new(opts))
|
276
276
|
|
277
277
|
method = client.next_method
|
278
278
|
|
279
|
-
client.check_response(method, Qrack::
|
279
|
+
client.check_response(method, Qrack::Protocol::Queue::UnbindOk, "Error unbinding queue #{name}")
|
280
280
|
|
281
281
|
# return message
|
282
282
|
:unbind_ok
|
@@ -291,6 +291,9 @@ module Bunny
|
|
291
291
|
# @option opts [Boolean] :nowait (false)
|
292
292
|
# Ignored by Bunny, always @false@.
|
293
293
|
#
|
294
|
+
# @option opts [Boolean] :nowait (false)
|
295
|
+
# Ignored by Bunny, always @false@.
|
296
|
+
#
|
294
297
|
# @return [Symbol] @:unsubscribe_ok@ if successful
|
295
298
|
def unsubscribe(opts = {})
|
296
299
|
# Default consumer_tag from subscription if not passed in
|
@@ -301,15 +304,15 @@ module Bunny
|
|
301
304
|
"No consumer tag received" if !consumer_tag
|
302
305
|
|
303
306
|
# Cancel consumer
|
304
|
-
client.send_frame(Qrack::
|
305
|
-
|
306
|
-
method = client.next_method
|
307
|
-
|
308
|
-
client.check_response(method, Qrack::Protocol09::Basic::CancelOk, "Error unsubscribing from queue #{name}")
|
307
|
+
client.send_frame(Qrack::Protocol::Basic::Cancel.new(:consumer_tag => consumer_tag, :nowait => false))
|
309
308
|
|
310
309
|
# Reset subscription
|
311
310
|
@default_consumer = nil
|
312
311
|
|
312
|
+
method = client.next_method
|
313
|
+
|
314
|
+
client.check_response(method, Qrack::Protocol::Basic::CancelOk, "Error unsubscribing from queue #{name}, got #{method.class}")
|
315
|
+
|
313
316
|
# Return confirmation
|
314
317
|
:unsubscribe_ok
|
315
318
|
end
|
@@ -317,7 +320,7 @@ module Bunny
|
|
317
320
|
private
|
318
321
|
|
319
322
|
def exchange
|
320
|
-
@exchange ||= Bunny::
|
323
|
+
@exchange ||= Bunny::Exchange.new(client, '', :type => :direct, :key => name, :reserved_1 => 0, :reserved_2 => false, :reserved_3 => false)
|
321
324
|
end
|
322
325
|
|
323
326
|
end
|