Parent

Included Modules

Class Index [+]

Quicksearch

AMQ::Client::Async::Queue

Attributes

name[R]

Qeueue name. May be server-generated or assigned directly. @return [String]

channel[R]

Channel this queue belongs to. @return [AMQ::Client::Channel]

consumers[R]

@return [Array] All consumers on this queue.

default_consumer[R]

@return [AMQ::Client::Consumer] Default consumer (registered with {Queue#consume}).

arguments[R]

@return [Hash] Additional arguments given on queue declaration. Typically used by AMQP extensions.

bindings[R]

@return [Array]

Public Class Methods

consumer_class() click to toggle source

@return [Class] AMQ::Client::Consumer or other class implementing consumer API. Used by libraries like {github.com/ruby-amqp/amqp Ruby amqp gem}. @api plugin

     # File lib/amq/client/async/queue.rb, line 250
250:         def self.consumer_class
251:           AMQ::Client::Async::Consumer
252:         end
new(connection, channel, name = AMQ::Protocol::EMPTY_STRING) click to toggle source

@param [AMQ::Client::Adapter] AMQ networking adapter to use. @param [AMQ::Client::Channel] AMQ channel this queue object uses. @param [String] Queue name. Please note that AMQP spec does not require brokers to support Unicode for queue names. @api public

    # File lib/amq/client/async/queue.rb, line 54
54:         def initialize(connection, channel, name = AMQ::Protocol::EMPTY_STRING)
55:           raise ArgumentError.new("queue name must not be nil; if you want broker to generate queue name for you, pass an empty string") if name.nil?
56: 
57:           super(connection)
58: 
59:           @name         = name
60:           # this has to stay true even after queue.declare-ok arrives. MK.
61:           @server_named = @name.empty?
62:           if @server_named
63:             self.on_connection_interruption do
64:               # server-named queue need to get new names after recovery. MK.
65:               @name = AMQ::Protocol::EMPTY_STRING
66:             end
67:           end
68: 
69:           @channel      = channel
70: 
71:           # primarily for autorecovery. MK.
72:           @bindings  = Array.new
73: 
74:           @consumers = Hash.new
75:         end

Public Instance Methods

acknowledge(delivery_tag) click to toggle source

Acknowledge a delivery tag. @return [Queue] self

@api public @see bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.8.3.13.)

     # File lib/amq/client/async/queue.rb, line 348
348:         def acknowledge(delivery_tag)
349:           @channel.acknowledge(delivery_tag)
350: 
351:           self
352:         end
after_connection_interruption(&block) click to toggle source
after_recovery(&block) click to toggle source
Alias for: on_recovery
auto_delete?() click to toggle source

@return [Boolean] true if this queue was declared as automatically deleted (deleted as soon as last consumer unbinds). @api public

    # File lib/amq/client/async/queue.rb, line 92
92:         def auto_delete?
93:           @auto_delete
94:         end
auto_recover() click to toggle source

Called by associated connection object when AMQP connection has been re-established (for example, after a network failure).

@api plugin

     # File lib/amq/client/async/queue.rb, line 427
427:         def auto_recover
428:           self.exec_callback_yielding_self(:before_recovery)
429:           self.redeclare do
430:             self.rebind
431: 
432:             @consumers.each { |tag, consumer| consumer.auto_recover }
433: 
434:             self.exec_callback_yielding_self(:after_recovery)
435:           end
436:         end
before_recovery(&block) click to toggle source

Defines a callback that will be executed after TCP connection is recovered after a network failure but before AMQP connection is re-opened. Only one callback can be defined (the one defined last replaces previously added ones).

@api public

     # File lib/amq/client/async/queue.rb, line 393
393:         def before_recovery(&block)
394:           self.redefine_callback(:before_recovery, &block)
395:         end
bind(exchange, routing_key = AMQ::Protocol::EMPTY_STRING, nowait = false, arguments = nil, &block) click to toggle source

@return [Queue] self

@api public @see bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.7.2.3.)

     # File lib/amq/client/async/queue.rb, line 186
186:         def bind(exchange, routing_key = AMQ::Protocol::EMPTY_STRING, nowait = false, arguments = nil, &block)
187:           nowait = true unless block
188:           exchange_name = if exchange.respond_to?(:name)
189:                             exchange.name
190:                           else
191: 
192:                             exchange
193:                           end
194: 
195:           @connection.send_frame(Protocol::Queue::Bind.encode(@channel.id, @name, exchange_name, routing_key, nowait, arguments))
196: 
197:           if !nowait
198:             self.append_callback(:bind, &block)
199:             @channel.queues_awaiting_bind_ok.push(self)
200:           end
201: 
202:           # store bindings for automatic recovery, but BE VERY CAREFUL to
203:           # not cause an infinite rebinding loop here when we recover. MK.
204:           binding = { :exchange => exchange_name, :routing_key => routing_key, :arguments => arguments }
205:           @bindings.push(binding) unless @bindings.include?(binding)
206: 
207:           self
208:         end
cancel(nowait = false, &block) click to toggle source

Unsubscribes from message delivery. @return [Queue] self

@api public @see bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.8.3.5.)

     # File lib/amq/client/async/queue.rb, line 275
275:         def cancel(nowait = false, &block)
276:           raise "There is no default consumer for this queue. This usually means that you are trying to unsubscribe a queue that never was subscribed for messages in the first place." if @default_consumer.nil?
277: 
278:           @default_consumer.cancel(nowait, &block)
279: 
280:           self
281:         end
consume(no_ack = false, exclusive = false, nowait = false, no_local = false, arguments = nil, &block) click to toggle source

@return [Queue] self

@api public @see bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.8.3.3.)

     # File lib/amq/client/async/queue.rb, line 260
260:         def consume(no_ack = false, exclusive = false, nowait = false, no_local = false, arguments = nil, &block)
261:           raise RuntimeError.new("This queue already has default consumer. Please instantiate AMQ::Client::Consumer directly to register additional consumers.") if @default_consumer
262: 
263:           nowait            = true unless block
264:           @default_consumer = self.class.consumer_class.new(@channel, self, generate_consumer_tag(@name), exclusive, no_ack, arguments, no_local, &block)
265:           @default_consumer.consume(nowait, &block)
266: 
267:           self
268:         end
declare(passive = false, durable = false, exclusive = false, auto_delete = false, nowait = false, arguments = nil, &block) click to toggle source

Declares this queue.

@return [Queue] self

@api public @see bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.7.2.1.)

     # File lib/amq/client/async/queue.rb, line 106
106:         def declare(passive = false, durable = false, exclusive = false, auto_delete = false, nowait = false, arguments = nil, &block)
107:           raise ArgumentError, "declaration with nowait does not make sense for server-named queues! Either specify name other than empty string or use #declare without nowait" if nowait && self.anonymous?
108: 
109:           # these two are for autorecovery. MK.
110:           @passive      = passive
111:           @server_named = @name.empty?
112: 
113:           @durable     = durable
114:           @exclusive   = exclusive
115:           @auto_delete = auto_delete
116:           @arguments   = arguments
117: 
118:           nowait = true if !block && !@name.empty?
119:           @connection.send_frame(Protocol::Queue::Declare.encode(@channel.id, @name, passive, durable, exclusive, auto_delete, nowait, arguments))
120: 
121:           if !nowait
122:             self.append_callback(:declare, &block)
123:             @channel.queues_awaiting_declare_ok.push(self)
124:           end
125: 
126:           self
127:         end
delete(if_unused = false, if_empty = false, nowait = false, &block) click to toggle source

Deletes this queue.

@param [Boolean] if_unused delete only if queue has no consumers (subscribers). @param [Boolean] if_empty delete only if queue has no messages in it. @param [Boolean] nowait Don’t wait for reply from broker. @return [Queue] self

@api public @see bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.7.2.9.)

     # File lib/amq/client/async/queue.rb, line 163
163:         def delete(if_unused = false, if_empty = false, nowait = false, &block)
164:           nowait = true unless block
165:           @connection.send_frame(Protocol::Queue::Delete.encode(@channel.id, @name, if_unused, if_empty, nowait))
166: 
167:           if !nowait
168:             self.append_callback(:delete, &block)
169: 
170:             # TODO: delete itself from queues cache
171:             @channel.queues_awaiting_delete_ok.push(self)
172:           end
173: 
174:           self
175:         end
durable?() click to toggle source

@return [Boolean] true if this queue was declared as durable (will survive broker restart). @api public

    # File lib/amq/client/async/queue.rb, line 80
80:         def durable?
81:           @durable
82:         end
exclusive?() click to toggle source

@return [Boolean] true if this queue was declared as exclusive (limited to just one consumer) @api public

    # File lib/amq/client/async/queue.rb, line 86
86:         def exclusive?
87:           @exclusive
88:         end
generate_consumer_tag(name) click to toggle source

Unique string supposed to be used as a consumer tag.

@return [String] Unique string. @api plugin

     # File lib/amq/client/async/queue.rb, line 450
450:         def generate_consumer_tag(name)
451:           "#{name}-#{Time.now.to_i * 1000}-#{Kernel.rand(999_999_999_999)}"
452:         end
get(no_ack = false, &block) click to toggle source

Fetches messages from the queue. @return [Queue] self

@api public @see bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.8.3.10.)

     # File lib/amq/client/async/queue.rb, line 303
303:         def get(no_ack = false, &block)
304:           @connection.send_frame(Protocol::Basic::Get.encode(@channel.id, @name, no_ack))
305: 
306:           # most people only want one callback per #get call. Consider the following example:
307:           #
308:           # 100.times { queue.get { ... } }
309:           #
310:           # most likely you won't expect 100 callback runs per message here. MK.
311:           self.redefine_callback(:get, &block)
312:           @channel.queues_awaiting_get_response.push(self)
313: 
314:           self
315:         end
handle_bind_ok(method) click to toggle source
     # File lib/amq/client/async/queue.rb, line 475
475:         def handle_bind_ok(method)
476:           self.exec_callback_once(:bind, method)
477:         end
handle_connection_interruption(method = nil) click to toggle source
     # File lib/amq/client/async/queue.rb, line 455
455:         def handle_connection_interruption(method = nil)
456:           @consumers.each { |tag, c| c.handle_connection_interruption(method) }
457:         end
handle_connection_interruption(method = nil) click to toggle source

@private

     # File lib/amq/client/async/queue.rb, line 382
382:         def handle_connection_interruption(method = nil)
383:           @consumers.each { |tag, consumer| consumer.handle_connection_interruption(method) }
384: 
385:           self.exec_callback_yielding_self(:after_connection_interruption)
386:         end
handle_declare_ok(method) click to toggle source
     # File lib/amq/client/async/queue.rb, line 460
460:         def handle_declare_ok(method)
461:           @name = method.queue if @name.empty?
462:           @channel.register_queue(self)
463: 
464:           self.exec_callback_once_yielding_self(:declare, method)
465:         end
handle_delete_ok(method) click to toggle source
     # File lib/amq/client/async/queue.rb, line 467
467:         def handle_delete_ok(method)
468:           self.exec_callback_once(:delete, method)
469:         end
handle_get_empty(method) click to toggle source
     # File lib/amq/client/async/queue.rb, line 488
488:         def handle_get_empty(method)
489:           method = Protocol::GetResponse.new(method)
490:           self.exec_callback(:get, method)
491:         end
handle_get_ok(method, header, payload) click to toggle source
     # File lib/amq/client/async/queue.rb, line 483
483:         def handle_get_ok(method, header, payload)
484:           method = Protocol::GetResponse.new(method)
485:           self.exec_callback(:get, method, header, payload)
486:         end
handle_purge_ok(method) click to toggle source
     # File lib/amq/client/async/queue.rb, line 471
471:         def handle_purge_ok(method)
472:           self.exec_callback_once(:purge, method)
473:         end
handle_unbind_ok(method) click to toggle source
     # File lib/amq/client/async/queue.rb, line 479
479:         def handle_unbind_ok(method)
480:           self.exec_callback_once(:unbind, method)
481:         end
on_connection_interruption(&block) click to toggle source

Defines a callback that will be executed after TCP connection is interrupted (typically because of a network failure). Only one callback can be defined (the one defined last replaces previously added ones).

@api public

     # File lib/amq/client/async/queue.rb, line 376
376:         def on_connection_interruption(&block)
377:           self.redefine_callback(:after_connection_interruption, &block)
378:         end
on_delivery(&block) click to toggle source

@api public @see bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Sections 1.8.3.9)

     # File lib/amq/client/async/queue.rb, line 293
293:         def on_delivery(&block)
294:           @default_consumer.on_delivery(&block)
295:         end
on_recovery(&block) click to toggle source

Defines a callback that will be executed when AMQP connection is recovered after a network failure.. Only one callback can be defined (the one defined last replaces previously added ones).

@api public

     # File lib/amq/client/async/queue.rb, line 409
409:         def on_recovery(&block)
410:           self.redefine_callback(:after_recovery, &block)
411:         end
Also aliased as: after_recovery
purge(nowait = false, &block) click to toggle source

Purges (removes all messagse from) the queue. @return [Queue] self

@api public @see bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.7.2.7.)

     # File lib/amq/client/async/queue.rb, line 324
324:         def purge(nowait = false, &block)
325:           nowait = true unless block
326:           @connection.send_frame(Protocol::Queue::Purge.encode(@channel.id, @name, nowait))
327: 
328:           if !nowait
329:             self.redefine_callback(:purge, &block)
330:             # TODO: handle channel & connection-level exceptions
331:             @channel.queues_awaiting_purge_ok.push(self)
332:           end
333: 
334:           self
335:         end
rebind(&block) click to toggle source

Used by automatic recovery machinery. @private @api plugin

     # File lib/amq/client/async/queue.rb, line 237
237:         def rebind(&block)
238:           @bindings.each { |b| self.bind(b[:exchange], b[:routing_key], true, b[:arguments]) }
239:         end
redeclare(&block) click to toggle source

Re-declares queue with the same attributes @api public

     # File lib/amq/client/async/queue.rb, line 131
131:         def redeclare(&block)
132:           nowait = true if !block && !@name.empty?
133: 
134:           # server-named queues get their new generated names.
135:           new_name = if @server_named
136:                        AMQ::Protocol::EMPTY_STRING
137:                      else
138:                        @name
139:                      end
140:           @connection.send_frame(Protocol::Queue::Declare.encode(@channel.id, new_name, @passive, @durable, @exclusive, @auto_delete, false, @arguments))
141: 
142:           if !nowait
143:             self.append_callback(:declare, &block)
144:             @channel.queues_awaiting_declare_ok.push(self)
145:           end
146: 
147:           self
148:         end
reject(delivery_tag, requeue = true) click to toggle source

@return [Queue] self

@api public @see bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.8.3.14.)

     # File lib/amq/client/async/queue.rb, line 359
359:         def reject(delivery_tag, requeue = true)
360:           @channel.reject(delivery_tag, requeue)
361: 
362:           self
363:         end
run_after_recovery_callbacks() click to toggle source

@private

     # File lib/amq/client/async/queue.rb, line 415
415:         def run_after_recovery_callbacks
416:           self.exec_callback_yielding_self(:after_recovery)
417: 
418:           @consumers.each { |tag, c| c.run_after_recovery_callbacks }
419:         end
run_before_recovery_callbacks() click to toggle source

@private

     # File lib/amq/client/async/queue.rb, line 398
398:         def run_before_recovery_callbacks
399:           self.exec_callback_yielding_self(:before_recovery)
400: 
401:           @consumers.each { |tag, c| c.run_before_recovery_callbacks }
402:         end
unbind(exchange, routing_key = AMQ::Protocol::EMPTY_STRING, arguments = nil, &block) click to toggle source

@return [Queue] self

@api public @see bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.7.2.5.)

     # File lib/amq/client/async/queue.rb, line 215
215:         def unbind(exchange, routing_key = AMQ::Protocol::EMPTY_STRING, arguments = nil, &block)
216:           exchange_name = if exchange.respond_to?(:name)
217:                             exchange.name
218:                           else
219: 
220:                             exchange
221:                           end
222: 
223:           @connection.send_frame(Protocol::Queue::Unbind.encode(@channel.id, @name, exchange_name, routing_key, arguments))
224: 
225:           self.append_callback(:unbind, &block)
226:           @channel.queues_awaiting_unbind_ok.push(self)
227: 
228: 
229:           @bindings.delete_if { |b| b[:exchange] == exchange_name }
230: 
231:           self
232:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.