Sha256: 097cd96515b45fea3109338da7bc2e9f2a684b460303987b4e7a4a014bacb83c

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 KB

Contents

class MessageQueue::Adapters::Bunny::Connection < MessageQueue::Connection
  attr_reader :connection

  # Public: Connect to RabbitMQ
  #
  # Returns the Bunny instance
  def connect
    @connection ||= begin
                      super
                      bunny = ::Bunny.new(bunny_settings)
                      bunny.start
                      bunny
                    end
  end

  # Public: Disconnect from RabbitMQ
  #
  # Returns nothing
  def disconnect
    if @connection
      super
      @connection.close if @connection.open?
      @connection = nil
    end
  end

  # Public: Check if it's connected to the message queue
  #
  # Returns true if it's connected
  def connected?
    @connection.open? if @connection
  end

  def new_producer(options)
    raise "No connection to RabbitMQ" unless connection

    Producer.new(self, options)
  end

  def new_consumer(options)
    raise "No connection to RabbitMQ" unless connection

    Consumer.new(self, options)
  end

  private

  def bunny_settings
    default_bunny_settings.merge(settings)
  end

  def default_bunny_settings
    {
      :heartbeat => 1,
      :automatically_recover => true,
      :network_recovery_interval => 1
    }
  end
end

require "message_queue/adapters/bunny/producer"
require "message_queue/adapters/bunny/consumer"

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
message_queue-0.1.1 lib/message_queue/adapters/bunny/connection.rb
message_queue-0.1.0 lib/message_queue/adapters/bunny/connection.rb