Object
# File lib/amq/client/async/exchange.rb, line 40 40: def initialize(connection, channel, name, type = :fanout) 41: if !(BUILTIN_TYPES.include?(type.to_sym) || type.to_s =~ /^x-.+/) 42: raise UnknownExchangeTypeError.new(BUILTIN_TYPES, type) 43: end 44: 45: @connection = connection 46: @channel = channel 47: @name = name 48: @type = type 49: 50: # register pre-declared exchanges 51: if @name == AMQ::Protocol::EMPTY_STRING || @name =~ /^amq\.(direct|fanout|topic|match|headers)/ 52: @channel.register_exchange(self) 53: end 54: 55: super(connection) 56: 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/exchange.rb, line 224 224: def auto_recover 225: self.redeclare unless predefined? 226: 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/amq/client/async/exchange.rb, line 195 195: def before_recovery(&block) 196: self.redefine_callback(:before_recovery, &block) 197: end
@return [Boolean] true if this exchange is of a custom type (begins with x-) @api public
# File lib/amq/client/async/exchange.rb, line 84 84: def custom_type? 85: @type.to_s =~ /^x-.+/ 86: end
@api public
# File lib/amq/client/async/exchange.rb, line 97 97: def declare(passive = false, durable = false, auto_delete = false, nowait = false, arguments = nil, &block) 98: # for re-declaration 99: @passive = passive 100: @durable = durable 101: @auto_delete = auto_delete 102: @arguments = arguments 103: 104: @connection.send_frame(Protocol::Exchange::Declare.encode(@channel.id, @name, @type.to_s, passive, durable, auto_delete, false, nowait, arguments)) 105: 106: unless nowait 107: self.define_callback(:declare, &block) 108: @channel.exchanges_awaiting_declare_ok.push(self) 109: end 110: 111: self 112: end
@api public
# File lib/amq/client/async/exchange.rb, line 132 132: def delete(if_unused = false, nowait = false, &block) 133: @connection.send_frame(Protocol::Exchange::Delete.encode(@channel.id, @name, if_unused, nowait)) 134: 135: unless nowait 136: self.define_callback(:delete, &block) 137: 138: # TODO: delete itself from exchanges cache 139: @channel.exchanges_awaiting_delete_ok.push(self) 140: end 141: 142: self 143: end
@return [Boolean] true if this exchange is of type `direct` @api public
# File lib/amq/client/async/exchange.rb, line 66 66: def direct? 67: @type == :direct 68: end
@return [Boolean] true if this exchange is of type `fanout` @api public
# File lib/amq/client/async/exchange.rb, line 60 60: def fanout? 61: @type == :fanout 62: end
@private
# File lib/amq/client/async/exchange.rb, line 184 184: def handle_connection_interruption(method = nil) 185: self.exec_callback_yielding_self(:after_connection_interruption) 186: end
Implementation
# File lib/amq/client/async/exchange.rb, line 237 237: def handle_declare_ok(method) 238: @name = method.exchange if self.anonymous? 239: @channel.register_exchange(self) 240: 241: self.exec_callback_once_yielding_self(:declare, method) 242: end
# File lib/amq/client/async/exchange.rb, line 244 244: def handle_delete_ok(method) 245: self.exec_callback_once(:delete, method) 246: end
@return [Boolean] true if this exchange is of type `headers` @api public
# File lib/amq/client/async/exchange.rb, line 78 78: def headers? 79: @type == :headers 80: 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/exchange.rb, line 178 178: def on_connection_interruption(&block) 179: self.redefine_callback(:after_connection_interruption, &block) 180: 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/amq/client/async/exchange.rb, line 209 209: def on_recovery(&block) 210: self.redefine_callback(:after_recovery, &block) 211: end
@api public
# File lib/amq/client/async/exchange.rb, line 161 161: def on_return(&block) 162: self.redefine_callback(:return, &block) 163: 164: self 165: end
@return [Boolean] true if this exchange is a pre-defined one (amq.direct, amq.fanout, amq.match and so on)
# File lib/amq/client/async/exchange.rb, line 89 89: def predefined? 90: @name && ((@name == AMQ::Protocol::EMPTY_STRING) || !!(@name =~ /^amq\.(direct|fanout|topic|headers|match)/)) 91: end
@api public
# File lib/amq/client/async/exchange.rb, line 150 150: def publish(payload, routing_key = AMQ::Protocol::EMPTY_STRING, user_headers = {}, mandatory = false, immediate = false, frame_size = nil) 151: headers = { :priority => 0, :delivery_mode => 2, :content_type => "application/octet-stream" }.merge(user_headers) 152: @connection.send_frameset(Protocol::Basic::Publish.encode(@channel.id, payload, headers, @name, routing_key, mandatory, immediate, (frame_size || @connection.frame_max)), @channel) 153: 154: # publisher confirms support. MK. 155: @channel.exec_callback(:after_publish) 156: self 157: end
@api public
# File lib/amq/client/async/exchange.rb, line 116 116: def redeclare(&block) 117: nowait = block.nil? 118: @connection.send_frame(Protocol::Exchange::Declare.encode(@channel.id, @name, @type.to_s, @passive, @durable, @auto_delete, false, nowait, @arguments)) 119: 120: unless nowait 121: self.define_callback(:declare, &block) 122: @channel.exchanges_awaiting_declare_ok.push(self) 123: end 124: 125: self 126: end
@private
# File lib/amq/client/async/exchange.rb, line 215 215: def run_after_recovery_callbacks 216: self.exec_callback_yielding_self(:after_recovery) 217: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.