Change publisher index. Publisher index is incremented by 1 after each Basic.Publish starting at 1. This is done on both client and server, hence this acknowledged messages can be matched via its delivery-tag.
@api private
# File lib/amq/client/async/extensions/rabbitmq/confirm.rb, line 197 def self.included(host) host.handle(Protocol::Confirm::SelectOk) do |connection, frame| method = frame.decode_payload channel = connection.channels[frame.channel] channel.handle_select_ok(method) end host.handle(Protocol::Basic::Ack) do |connection, frame| method = frame.decode_payload channel = connection.channels[frame.channel] channel.handle_basic_ack(method) end host.handle(Protocol::Basic::Nack) do |connection, frame| method = frame.decode_payload channel = connection.channels[frame.channel] channel.handle_basic_nack(method) end end
Turn on confirmations for this channel and, if given, register callback for Confirm.Select-Ok.
@raise [RuntimeError] Occurs when confirmations are already activated. @raise [RuntimeError] Occurs when nowait is true and block is given.
@param [Boolean] nowait Whether we expect Confirm.Select-Ok to be returned by the broker or not. @yield [method] Callback which will be executed once we receive Confirm.Select-Ok. @yieldparam [AMQ::Protocol::Confirm::SelectOk] method Protocol method class instance.
@return [self] self.
@see confirm
# File lib/amq/client/async/extensions/rabbitmq/confirm.rb, line 100 def confirm_select(nowait = false, &block) if nowait && block raise ArgumentError, "confirm.select with nowait = true and a callback makes no sense" end @uses_publisher_confirmations = true reset_publisher_index! self.redefine_callback(:confirm_select, &block) unless nowait self.redefine_callback(:after_publish) do increment_publisher_index! end @connection.send_frame(Protocol::Confirm::Select.encode(@id, nowait)) self end
Handler for Basic.Ack. By default, it just executes hook specified via the confirm method with a single argument, a protocol method class instance (an instance of AMQ::Protocol::Basic::Ack).
@api plugin
# File lib/amq/client/async/extensions/rabbitmq/confirm.rb, line 174 def handle_basic_ack(method) self.exec_callback(:ack, method) end
Handler for Basic.Nack. By default, it just executes hook specified via the confirm_failed method with a single argument, a protocol method class instance (an instance of AMQ::Protocol::Basic::Nack).
@api plugin
# File lib/amq/client/async/extensions/rabbitmq/confirm.rb, line 185 def handle_basic_nack(method) self.exec_callback(:nack, method) end
Handler for Confirm.Select-Ok. By default, it just executes hook specified via the confirmations method with a single argument, a protocol method class instance (an instance of AMQ::Protocol::Confirm::SelectOk) and then it deletes the callback, since Confirm.Select is supposed to be sent just once.
@api plugin
# File lib/amq/client/async/extensions/rabbitmq/confirm.rb, line 164 def handle_select_ok(method) self.exec_callback_once(:confirm_select, method) end
This method is executed after publishing of each message via {Exchage#publish}. Currently it just increments publisher index by 1, so messages can be actually matched.
@api plugin
# File lib/amq/client/async/extensions/rabbitmq/confirm.rb, line 83 def increment_publisher_index! @publisher_index += 1 end
Turn on confirmations for this channel and, if given, register callback for basic.ack from the broker.
@raise [RuntimeError] Occurs when confirmations are already activated. @raise [RuntimeError] Occurs when nowait is true and block is given. @param [Boolean] nowait Whether we expect Confirm.Select-Ok to be returned by the broker or not.
@yield [basick_ack] Callback which will be executed every time we receive Basic.Ack from the broker. @yieldparam [AMQ::Protocol::Basic::Ack] basick_ack Protocol method class instance.
@return [self] self.
# File lib/amq/client/async/extensions/rabbitmq/confirm.rb, line 134 def on_ack(nowait = false, &block) self.use_publisher_confirmations! unless self.uses_publisher_confirmations? self.define_callback(:ack, &block) if block self end
Register error callback for Basic.Nack. It's called when message(s) is rejected.
@return [self] self
# File lib/amq/client/async/extensions/rabbitmq/confirm.rb, line 147 def on_nack(&block) self.define_callback(:nack, &block) if block self end
Publisher index is an index of the last message since the confirmations were activated, started with 0. It's incremented by 1 every time a message is published. This is done on both client and server, hence this acknowledged messages can be matched via its delivery-tag.
@return [Integer] Current publisher index. @api public
# File lib/amq/client/async/extensions/rabbitmq/confirm.rb, line 66 def publisher_index @publisher_index ||= 0 end
Resets publisher index to 0
@api plugin
# File lib/amq/client/async/extensions/rabbitmq/confirm.rb, line 73 def reset_publisher_index! @publisher_index = 0 end
Generated with the Darkfish Rdoc Generator 2.