class MessageDriver::Adapters::BunnyAdapter

Constants

NETWORK_ERRORS

Attributes

ack_key[R]

Public Class Methods

new(broker, config) click to toggle source
# File lib/message_driver/adapters/bunny_adapter.rb, line 255
def initialize(broker, config)
  validate_bunny_version
  @broker = broker
  @config = config
  @ack_key = :manual_ack
end

Public Instance Methods

build_context() click to toggle source
# File lib/message_driver/adapters/bunny_adapter.rb, line 288
def build_context
  BunnyContext.new(self)
end
connection(ensure_started = true) click to toggle source
# File lib/message_driver/adapters/bunny_adapter.rb, line 264
def connection(ensure_started = true)
  if ensure_started
    begin
      @connection ||= Bunny::Session.new(@config)
      @connection.start
    rescue *NETWORK_ERRORS => e
      raise MessageDriver::ConnectionError.new(e.to_s, e)
    rescue => e
      stop
      raise e
    end
  end
  @connection
end
new_subscription_context(subscription) click to toggle source
# File lib/message_driver/adapters/bunny_adapter.rb, line 292
def new_subscription_context(subscription)
  ctx = new_context
  ctx.channel = connection.create_channel
  ctx.subscription = subscription
  ctx
end
stop() click to toggle source
Calls superclass method MessageDriver::Adapters::Base#stop
# File lib/message_driver/adapters/bunny_adapter.rb, line 279
def stop
  super
  @connection.close unless @connection.nil?
rescue => e
  logger.error "error while attempting connection close\n#{exception_to_str(e)}"
ensure
  @connection = nil
end

Private Instance Methods

log_errors() { || ... } click to toggle source
# File lib/message_driver/adapters/bunny_adapter.rb, line 543
def log_errors
  yield
rescue => e
  logger.error exception_to_str(e)
end
validate_bunny_version() click to toggle source
# File lib/message_driver/adapters/bunny_adapter.rb, line 549
def validate_bunny_version
  required = Gem::Requirement.create('>= 2.7.0')
  current = Gem::Version.create(Bunny::VERSION)
  unless required.satisfied_by? current
    raise MessageDriver::Error, 'bunny 1.7.0 or later is required for the bunny adapter'
  end
end