Class/Module Index [+]

Quicksearch

AMQ::Client::Async::Extensions::RabbitMQ::Confirm::ChannelMixin

Attributes

publisher_index[W]

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

Public Class Methods

included(host) click to toggle source
# 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

Public Instance Methods

confirm_select(nowait = false, &block) click to toggle source

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
handle_basic_ack(method) click to toggle source

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
handle_basic_nack(method) click to toggle source

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
handle_select_ok(method) click to toggle source

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
increment_publisher_index!() click to toggle source

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
on_ack(nowait = false, &block) click to toggle source

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
on_nack(&block) click to toggle source

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() click to toggle source

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
reset_publisher_index!() click to toggle source

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
reset_state!() click to toggle source
# File lib/amq/client/async/extensions/rabbitmq/confirm.rb, line 190
def reset_state!
  super

  @uses_publisher_confirmations = false
end
uses_publisher_confirmations?() click to toggle source

@return [Boolean]

# File lib/amq/client/async/extensions/rabbitmq/confirm.rb, line 118
def uses_publisher_confirmations?
  @uses_publisher_confirmations
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.