Object
# File lib/amq/client/async/channel.rb, line 39 39: def initialize(connection, id, options = {}) 40: super(connection) 41: 42: @id = id 43: @exchanges = Hash.new 44: @queues = Hash.new 45: @consumers = Hash.new 46: @options = { :auto_recovery => connection.auto_recovering? }.merge(options) 47: @auto_recovery = (!!@options[:auto_recovery]) 48: 49: # we must synchronize frameset delivery. MK. 50: @mutex = Mutex.new 51: 52: reset_state! 53: 54: # 65536 is here for cases when channel is opened without passing a callback in, 55: # otherwise channel_mix would be nil and it causes a lot of needless headaches. 56: # lets just have this default. MK. 57: channel_max = if @connection.open? 58: @connection.channel_max || 65536 59: else 60: 65536 61: end 62: 63: if channel_max != 0 && !(0..channel_max).include?(id) 64: raise ArgumentError.new("Max channel for the connection is #{channel_max}, given: #{id}") 65: end 66: end
Acknowledge one or all messages on the channel.
@api public @see bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.8.3.13.)
# File lib/amq/client/async/channel.rb, line 137 137: def acknowledge(delivery_tag, multiple = false) 138: @connection.send_frame(Protocol::Basic::Ack.encode(self.id, delivery_tag, multiple)) 139: 140: self 141: end
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/channel.rb, line 322 322: def auto_recover 323: return unless auto_recovering? 324: 325: self.open do 326: # exchanges must be recovered first because queue recovery includes recovery of bindings. MK. 327: @exchanges.each { |name, e| e.auto_recover } 328: @queues.each { |name, q| q.auto_recover } 329: end 330: end
@return [Boolean] true if this channel uses automatic recovery mode
# File lib/amq/client/async/channel.rb, line 69 69: def auto_recovering? 70: @auto_recovery 71: end
Defines a callback that will be executed after TCP connection has 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/channel.rb, line 286 286: def before_recovery(&block) 287: self.redefine_callback(:before_recovery, &block) 288: end
Closes AMQP channel.
@api public
# File lib/amq/client/async/channel.rb, line 121 121: def close(reply_code = 200, reply_text = DEFAULT_REPLY_TEXT, class_id = 0, method_id = 0, &block) 122: @connection.send_frame(Protocol::Channel::Close.encode(@id, reply_code, reply_text, class_id, method_id)) 123: 124: self.redefine_callback :close, &block 125: end
AMQP connection this channel belongs to.
@return [AMQ::Client::Connection] Connection this channel belongs to.
# File lib/amq/client/async/channel.rb, line 93 93: def connection 94: @connection 95: end
@return [Hash
# File lib/amq/client/async/channel.rb, line 75 75: def consumers 76: @consumers 77: end
@return [Array
# File lib/amq/client/async/channel.rb, line 85 85: def exchanges 86: @exchanges.values 87: end
Finds exchange in the exchanges cache on this channel by name. Exchange only exists in the cache if it was previously instantiated on this channel.
@param [String] name Exchange name @return [AMQ::Client::Exchange] Exchange (if found) @api plugin
# File lib/amq/client/async/channel.rb, line 351 351: def find_exchange(name) 352: @exchanges[name] 353: end
@api plugin @private
# File lib/amq/client/async/channel.rb, line 365 365: def find_queue(name) 366: @queues[name] 367: end
Asks the peer to pause or restart the flow of content data sent to a consumer. This is a simple flowcontrol mechanism that a peer can use to avoid overflowing its queues or otherwise finding itself receiving more messages than it can process. Note that this method is not intended for window control. It does not affect contents returned to Queue#get callers.
@param [Boolean] active Desired flow state.
@see bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.5.2.3.) @api public
# File lib/amq/client/async/channel.rb, line 196 196: def flow(active = false, &block) 197: @connection.send_frame(Protocol::Channel::Flow.encode(@id, active)) 198: 199: self.redefine_callback :flow, &block 200: self 201: end
@return [Boolean] True if flow in this channel is active (messages will be delivered to consumers that use this channel).
@api public
# File lib/amq/client/async/channel.rb, line 206 206: def flow_is_active? 207: @flow_is_active 208: end
@api plugin @private
# File lib/amq/client/async/channel.rb, line 413 413: def handle_close(channel_close) 414: self.status = :closed 415: self.connection.clear_frames_on(self.id) 416: self.exec_callback_yielding_self(:error, channel_close) 417: 418: self.handle_connection_interruption(channel_close) 419: end
@api plugin @private
# File lib/amq/client/async/channel.rb, line 405 405: def handle_close_ok(close_ok) 406: self.status = :closed 407: self.connection.clear_frames_on(self.id) 408: self.exec_callback_once_yielding_self(:close, close_ok) 409: end
@private
# File lib/amq/client/async/channel.rb, line 272 272: def handle_connection_interruption(method = nil) 273: @queues.each { |name, q| q.handle_connection_interruption(method) } 274: @exchanges.each { |name, e| e.handle_connection_interruption(method) } 275: 276: self.exec_callback_yielding_self(:after_connection_interruption) 277: self.reset_state! 278: end
@api plugin @private
# File lib/amq/client/async/channel.rb, line 398 398: def handle_open_ok(open_ok) 399: self.status = :opened 400: self.exec_callback_once_yielding_self(:open, open_ok) 401: 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/amq/client/async/channel.rb, line 266 266: def on_connection_interruption(&block) 267: self.redefine_callback(:after_connection_interruption, &block) 268: end
Defines a callback that will be executed when channel is closed after channel-level exception.
@api public
# File lib/amq/client/async/channel.rb, line 257 257: def on_error(&block) 258: self.define_callback(:error, &block) 259: end
Defines a callback that will be executed after AMQP connection has 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/channel.rb, line 304 304: def on_recovery(&block) 305: self.redefine_callback(:after_recovery, &block) 306: end
Opens AMQP channel.
@api public
# File lib/amq/client/async/channel.rb, line 109 109: def open(&block) 110: @connection.send_frame(Protocol::Channel::Open.encode(@id, AMQ::Protocol::EMPTY_STRING)) 111: @connection.channels[@id] = self 112: self.status = :opening 113: 114: self.redefine_callback :open, &block 115: end
Requests a specific quality of service. The QoS can be specified for the current channel or for all channels on the connection.
@note RabbitMQ as of 2.3.1 does not support prefetch_size. @api public
# File lib/amq/client/async/channel.rb, line 179 179: def qos(prefetch_size = 0, prefetch_count = 32, global = false, &block) 180: @connection.send_frame(Protocol::Basic::Qos.encode(@id, prefetch_size, prefetch_count, global)) 181: 182: self.redefine_callback :qos, &block 183: self 184: end
@return [Array
# File lib/amq/client/async/channel.rb, line 80 80: def queues 81: @queues.values 82: end
Notifies AMQ broker that consumer has recovered and unacknowledged messages need to be redelivered.
@return [Channel] self
@note RabbitMQ as of 2.3.1 does not support basic.recover with requeue = false. @see bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.8.3.16.) @api public
# File lib/amq/client/async/channel.rb, line 161 161: def recover(requeue = true, &block) 162: @connection.send_frame(Protocol::Basic::Recover.encode(@id, requeue)) 163: 164: self.redefine_callback :recover, &block 165: self 166: end
Implementation
# File lib/amq/client/async/channel.rb, line 339 339: def register_exchange(exchange) 340: raise ArgumentError, "argument is nil!" if exchange.nil? 341: 342: @exchanges[exchange.name] = exchange 343: end
@api plugin @private
# File lib/amq/client/async/channel.rb, line 357 357: def register_queue(queue) 358: raise ArgumentError, "argument is nil!" if queue.nil? 359: 360: @queues[queue.name] = queue 361: end
Reject a message with given delivery tag.
@api public @see bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.8.3.14.)
# File lib/amq/client/async/channel.rb, line 147 147: def reject(delivery_tag, requeue = true) 148: @connection.send_frame(Protocol::Basic::Reject.encode(self.id, delivery_tag, requeue)) 149: 150: self 151: end
@api plugin @private
# File lib/amq/client/async/channel.rb, line 375 375: def reset_state! 376: @flow_is_active = true 377: 378: @queues_awaiting_declare_ok = Array.new 379: @exchanges_awaiting_declare_ok = Array.new 380: 381: @queues_awaiting_delete_ok = Array.new 382: 383: @exchanges_awaiting_delete_ok = Array.new 384: @queues_awaiting_purge_ok = Array.new 385: @queues_awaiting_bind_ok = Array.new 386: @queues_awaiting_unbind_ok = Array.new 387: @consumers_awaiting_consume_ok = Array.new 388: @consumers_awaiting_cancel_ok = Array.new 389: 390: @queues_awaiting_get_response = Array.new 391: 392: @callbacks = @callbacks.delete_if { |k, v| !RECOVERY_EVENTS.include?(k) } 393: end
@private
# File lib/amq/client/async/channel.rb, line 310 310: def run_after_recovery_callbacks 311: self.exec_callback_yielding_self(:after_recovery) 312: 313: @queues.each { |name, q| q.run_after_recovery_callbacks } 314: @exchanges.each { |name, e| e.run_after_recovery_callbacks } 315: end
@private
# File lib/amq/client/async/channel.rb, line 291 291: def run_before_recovery_callbacks 292: self.exec_callback_yielding_self(:before_recovery) 293: 294: @queues.each { |name, q| q.run_before_recovery_callbacks } 295: @exchanges.each { |name, e| e.run_before_recovery_callbacks } 296: end
Synchronizes given block using this channel’s mutex. @api public
# File lib/amq/client/async/channel.rb, line 99 99: def synchronize(&block) 100: @mutex.synchronize(&block) 101: end
Commits AMQP transaction.
@api public
# File lib/amq/client/async/channel.rb, line 230 230: def tx_commit(&block) 231: @connection.send_frame(Protocol::Tx::Commit.encode(@id)) 232: 233: self.redefine_callback :tx_commit, &block 234: self 235: end
Rolls AMQP transaction back.
@api public
# File lib/amq/client/async/channel.rb, line 240 240: def tx_rollback(&block) 241: @connection.send_frame(Protocol::Tx::Rollback.encode(@id)) 242: 243: self.redefine_callback :tx_rollback, &block 244: self 245: end
Sets the channel to use standard transactions. One must use this method at least once on a channel before using # or tx_rollback methods.
@api public
# File lib/amq/client/async/channel.rb, line 220 220: def tx_select(&block) 221: @connection.send_frame(Protocol::Tx::Select.encode(@id)) 222: 223: self.redefine_callback :tx_select, &block 224: self 225: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.