Sha256: 99f2dab093e9d9d5ad13426a2a4f1164ad46012fbca22a038e4adf98fc10a6c8

Contents?: true

Size: 907 Bytes

Versions: 2

Compression:

Stored size: 907 Bytes

Contents

require 'yaml'
require 'mq'

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

    @@instance = nil

    class << self

      def instance
        @instance ||= new
      end

      private :new

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

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

    def run(&block)
      # Ensure graceful shutdown of the connection to the broker
      DaemonKit.trap('INT') { ::AMQP.stop { ::EM.stop } }
      DaemonKit.trap('TERM') { ::AMQP.stop { ::EM.stop } }

      # Start our event loop and AMQP client
      DaemonKit.logger.debug("AMQP.connect(#{@config.inspect})")
      ::AMQP.connect(@config, &block)
      # ::AMQP.start(@config, &block)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
amqp-daemon-kit-1.0.1 lib/daemon_kit/dk_amqp.rb
amqp-daemon-kit-0.1.8.2 lib/daemon_kit/dk_amqp.rb