Class: DaemonKit::AMQP

Inherits:
Object
  • Object
show all
Defined in:
lib/daemon_kit/dk_amqp.rb

Overview

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

Constant Summary

@@instance =
nil

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (AMQP) initialize(config = {})



25
26
27
# File 'lib/daemon_kit/dk_amqp.rb', line 25

def initialize( config = {} )
  @config = DaemonKit::Config.load('amqp').to_h( true )
end

Class Method Details

+ (Object) instance



14
15
16
# File 'lib/daemon_kit/dk_amqp.rb', line 14

def instance
  @instance ||= new
end

+ (Object) run(&block)



20
21
22
# File 'lib/daemon_kit/dk_amqp.rb', line 20

def run(&block)
  instance.run(&block)
end

Instance Method Details

- (Object) run(&block)



29
30
31
32
33
34
35
36
37
38
39
40
# 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