Parent

Included Modules

Class/Module Index [+]

Quicksearch

Chef::IndexQueue::AmqpClient

Constants

VNODES

Public Class Methods

new() click to toggle source
# File lib/chef/index_queue/amqp_client.rb, line 26
def initialize
  reset!
end

Public Instance Methods

amqp_client() click to toggle source
# File lib/chef/index_queue/amqp_client.rb, line 40
def amqp_client
  unless @amqp_client
    begin
      @amqp_client = Bunny.new(amqp_opts)
      Chef::Log.debug "Starting AMQP connection with client settings: #{@amqp_client.inspect}"
      @amqp_client.start
      @amqp_client.qos(:prefetch_count => 1)
    rescue Bunny::ServerDownError => e
      Chef::Log.fatal "Could not connect to rabbitmq. Is it running, reachable, and configured correctly?"
      raise e
    rescue Bunny::ProtocolError => e
      Chef::Log.fatal "Connection to rabbitmq refused. Check your rabbitmq configuration and chef's amqp* settings"
      raise e
    end
  end
  @amqp_client
end
disconnected!() click to toggle source
# File lib/chef/index_queue/amqp_client.rb, line 62
def disconnected!
  Chef::Log.error("Disconnected from the AMQP Broker (RabbitMQ)")
  @amqp_client = nil
  reset!
end
exchange() click to toggle source
# File lib/chef/index_queue/amqp_client.rb, line 58
def exchange
  @exchange ||= amqp_client.exchange("chef-indexer", :durable => true, :type => :fanout)
end
queue_for_object(obj_id) click to toggle source
# File lib/chef/index_queue/amqp_client.rb, line 68
def queue_for_object(obj_id)
  retries = 0
  vnode_tag = obj_id_to_int(obj_id) % VNODES
  begin
    yield amqp_client.queue("vnode-#{vnode_tag}", :passive => false, :durable => true, :exclusive => false, :auto_delete => false)
  rescue Bunny::ServerDownError, Bunny::ConnectionError, Errno::ECONNRESET
    disconnected!
    if (retries += 1) < 2
      Chef::Log.info("Attempting to reconnect to the AMQP broker")
      retry
    else
      Chef::Log.fatal("Could not re-connect to the AMQP broker, giving up")
      raise
    end
  end
end
reset!() click to toggle source
# File lib/chef/index_queue/amqp_client.rb, line 30
def reset!
  @amqp_client && amqp_client.connected? && amqp_client.stop
  @amqp_client = nil
  @exchange = nil
end
stop() click to toggle source
# File lib/chef/index_queue/amqp_client.rb, line 36
def stop
  @amqp_client && @amqp_client.stop
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.