AMQ::Client::Async::Consumer
AMQP consumers are entities that handle messages delivered to them (“push API” as opposed to “pull API”) by AMQP broker. Every consumer is associated with a queue. Consumers can be exclusive (no other consumers can be registered for the same queue) or not (consumers share the queue). In the case of multiple consumers per queue, messages are distributed in round robin manner with respect to channel-level prefetch setting).
@see AMQP::Queue @see AMQP::Queue#subscribe @see AMQP::Queue#cancel
# File lib/amqp/consumer.rb, line 42 42: def initialize(channel, queue, consumer_tag = nil, exclusive = false, no_ack = false, arguments = {}, no_local = false) 43: super(channel, queue, (consumer_tag || self.class.tag_generator.generate_for(queue)), exclusive, no_ack, arguments, no_local) 44: end
@return [AMQ::Client::ConsumerTagGenerator] Consumer tag generator
# File lib/amqp/consumer.rb, line 31 31: def self.tag_generator 32: @tag_generator ||= AMQ::Client::ConsumerTagGenerator.new 33: end
@param [AMQ::Client::ConsumerTagGenerator] Assigns consumer tag generator that will be used by consumer instances @return [AMQ::Client::ConsumerTagGenerator] Provided argument
# File lib/amqp/consumer.rb, line 37 37: def self.tag_generator=(generator) 38: @tag_generator = generator 39: end
Acknowledge a delivery tag. @return [Consumer] self
@api public @see bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Section 1.8.3.13.)
# File lib/amqp/consumer.rb, line 143 143: def acknowledge(delivery_tag) 144: super(delivery_tag) 145: end
Called by associated connection object when AMQP connection has been re-established (for example, after a network failure).
@api plugin
# File lib/amqp/consumer.rb, line 194 194: def auto_recover 195: super 196: end
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/amqp/consumer.rb, line 176 176: def before_recovery(&block) 177: super(&block) 178: end
Legacy {AMQP::Queue} API compatibility. @private @deprecated
# File lib/amqp/consumer.rb, line 104 104: def callback 105: if @callbacks[:delivery] 106: @callbacks[:delivery].first 107: end 108: end
@return [AMQP::Consumer] self
# File lib/amqp/consumer.rb, line 83 83: def cancel(nowait = false, &block) 84: @channel.once_open do 85: @queue.once_declared do 86: super(nowait, &block) 87: end 88: end 89: 90: self 91: end
Begin consuming messages from the queue @return [AMQP::Consumer] self
# File lib/amqp/consumer.rb, line 55 55: def consume(nowait = false, &block) 56: @channel.once_open do 57: @queue.once_declared do 58: super(nowait, &block) 59: end 60: end 61: 62: self 63: end
@return [Boolean] true if this consumer is exclusive (other consumers for the same queue are not allowed)
# File lib/amqp/consumer.rb, line 47 47: def exclusive? 48: super 49: end
@return [String] Readable representation of relevant object state.
# File lib/amqp/consumer.rb, line 202 202: def inspect 203: "#<AMQP::Consumer:#{@consumer_tag}> queue=#{@queue.name} channel=#{@channel.id} callbacks=#{@callbacks.inspect}" 204: end
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/amqp/consumer.rb, line 165 165: def on_connection_interruption(&block) 166: super(&block) 167: end
Register a block that will be used to handle delivered messages.
@return [AMQP::Consumer] self @see AMQP::Queue#subscribe
# File lib/amqp/consumer.rb, line 115 115: def on_delivery(&block) 116: # We have to maintain this multiple arities jazz 117: # because older versions this gem are used in examples in at least 3 118: # books published by O'Reilly :(. MK. 119: delivery_shim = Proc.new { |basic_deliver, headers, payload| 120: case block.arity 121: when 1 then 122: block.call(payload) 123: when 2 then 124: h = Header.new(@channel, basic_deliver, headers.decode_payload) 125: block.call(h, payload) 126: else 127: h = Header.new(@channel, basic_deliver, headers.decode_payload) 128: block.call(h, payload, basic_deliver.consumer_tag, basic_deliver.delivery_tag, basic_deliver.redelivered, basic_deliver.exchange, basic_deliver.routing_key) 129: end 130: } 131: 132: super(&delivery_shim) 133: end
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/amqp/consumer.rb, line 184 184: def on_recovery(&block) 185: super(&block) 186: end
@return [Consumer] self
@api public @see bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Section 1.8.3.14.)
# File lib/amqp/consumer.rb, line 152 152: def reject(delivery_tag, requeue = true) 153: super(delivery_tag, requeue) 154: end
Used by automatic recovery code. @api plugin @return [AMQP::Consumer] self
# File lib/amqp/consumer.rb, line 68 68: def resubscribe(&block) 69: @channel.once_open do 70: @queue.once_declared do 71: self.unregister_with_channel 72: @consumer_tag = self.class.tag_generator.generate_for(@queue) 73: self.register_with_channel 74: 75: super(&block) 76: end 77: end 78: 79: self 80: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.