Sha256: dd33897e9941ddffece0bb41b186fa30e7fb50f4d8f5df14c0aa1b15e037eefd

Contents?: true

Size: 1.26 KB

Versions: 3

Compression:

Stored size: 1.26 KB

Contents

require 'bunny'
module RailwayIpc
  module Rabbitmq
    module Connection

      def self.included(klass)
        klass.extend(ClassMethods)
      end

      def self.create_bunny_connection(opts={automatic_recovery: true})
        settings = AMQ::Settings.parse_amqp_url(ENV["RAILWAY_RABBITMQ_CONNECTION_URL"])
        Bunny.new(
          host: settings[:host],
          user: settings[:user],
          pass: settings[:pass],
          port: settings[:port],
          automatic_recovery: opts[:automatic_recovery],
          logger: RailwayIpc.bunny_logger)
      end

      def initialize(queue=nil, pool=nil, opts={automatic_recovery: true})
        @connection = RailwayIpc::Rabbitmq::Connection.create_bunny_connection(opts)
        connection.start
        @channel = connection.create_channel
      end

      def stop
        channel.close
        connection.close
      end

      private

      attr_reader :channel, :exchange, :queue, :connection

      module ClassMethods
        def queue(queue)
          @queue_name = queue
        end

        def queue_name
          @queue_name
        end

        def exchange(exchange)
          @exchange_name = exchange
        end

        def exchange_name
          @exchange_name
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
railway-ipc-0.1.3 lib/railway_ipc/rabbitmq/connection.rb
railway-ipc-0.1.2 lib/railway_ipc/rabbitmq/connection.rb
railway-ipc-0.1.1 lib/railway_ipc/rabbitmq/connection.rb