class DaemonKit::AMQP

Thin wrapper around the amqp gem, specifically designed to ease configuration of a AMQP consumer daemon and provide some added simplicity

Public Class Methods

instance() click to toggle source
# File lib/daemon_kit/dk_amqp.rb, line 14
def instance
  @instance ||= new
end
new( config = {} ) click to toggle source
# File lib/daemon_kit/dk_amqp.rb, line 25
def initialize( config = {} )
  @config = DaemonKit::Config.load('amqp').to_h( true )
end
run(&block) click to toggle source
# File lib/daemon_kit/dk_amqp.rb, line 20
def run(&block)
  instance.run(&block)
end

Public Instance Methods

run() { |connection| ... } click to toggle source
# File lib/daemon_kit/dk_amqp.rb, line 29
def run(&block)
  # Start our event loop and AMQP client
  DaemonKit.logger.debug("AMQP.start(#{@config.inspect})")
  ::AMQP.start(@config) do |connection|
    # Ensure graceful shutdown of the connection to the broker
    hook = Proc.new { connection.close { EventMachine.stop } }
    DaemonKit.trap('INT', hook)
    DaemonKit.trap('TERM', hook)

    yield connection
  end
end