Sha256: b18251bc5b883997ac2e91d30369c185efa4959ed6600bbda948dbc2f6718161

Contents?: true

Size: 865 Bytes

Versions: 6

Compression:

Stored size: 865 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.start(#{@config.inspect})")
      ::AMQP.start(@config, &block)
    end
  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
amqp-daemon-kit-0.1.8.1 lib/daemon_kit/dk_amqp.rb
daemon-kit-0.1.8.1 lib/daemon_kit/dk_amqp.rb
daemon-kit-0.1.8 lib/daemon_kit/amqp.rb
daemon-kit-0.1.8rc3 lib/daemon_kit/amqp.rb
textgoeshere-daemon-kit-0.1.8.31 lib/daemon_kit/amqp.rb
textgoeshere-daemon-kit-0.1.8rc3 lib/daemon_kit/amqp.rb