Sha256: 712a5a45a3b67c49288bb9c834ae8a0d6bcb651581c90d88add0b89ae5c2becf

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 KB

Contents

require "message_queue/logging"

class MessageQueue::Connection
  include MessageQueue::Logging

  attr_reader :serializer, :settings

  # Public: Initialize a new Bunny connection.
  #
  # serializer - The Serializer for dumping and loading payload.
  #
  # settings   - The Hash settings used to connect.
  #
  #
  # Returns a Connection wrapper for Bunny.
  def initialize(serializer, settings)
    @serializer = serializer
    @settings = settings
  end

  # Public: Connect to the message queue
  #
  # Returns nothing
  def connect
    logger.info("Connecting to message queue with adapter #{self.class} and settings #{settings}")
  end

  # Public: Disconnect from the message queue
  #
  # Returns nothing
  def disconnect
    logger.info("Disconnecting from message queue")
  end

  # Public: Check if it's connected to the message queue
  #
  # Returns true if it's connected
  def connected?
    false
  end

  # Public: Connect to the message, execute the block and disconnect
  #
  # Returns nothing
  def with_connection(&block)
    begin
      connect
      block.call(self)
    ensure
      disconnect
    end
  end

  def new_producer(options = {})
    Producer.new(self, options)
  end

  def new_consumer(options = {})
    Consumer.new(self, options)
  end
end

require "message_queue/producer"
require "message_queue/consumer"

Version data entries

2 entries across 2 versions & 1 rubygems

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