class Rabbithole::Connection

Constants

DEFAULT_QUEUE
QUEUE_PREFIX

Public Class Methods

channel() click to toggle source
# File lib/rabbithole/connection.rb, line 45
def channel
  @channel ||= create_channel
end
configuration() click to toggle source
# File lib/rabbithole/connection.rb, line 41
def configuration
  @configuration ||= Settings.to_url
end
create_channel(worker_pool_size = 1, name = nil) click to toggle source
# File lib/rabbithole/connection.rb, line 37
def create_channel(worker_pool_size = 1, name = nil)
  self.session.create_channel(name, worker_pool_size)
end
default_queue() click to toggle source
# File lib/rabbithole/connection.rb, line 17
def default_queue
  queue DEFAULT_QUEUE
end
get_queue_name(queue) click to toggle source
# File lib/rabbithole/connection.rb, line 21
def get_queue_name(queue)
  "#{QUEUE_PREFIX}.#{queue}"
end
publish(queue_name, payload) click to toggle source
# File lib/rabbithole/connection.rb, line 10
def publish(queue_name, payload)
  channel = create_channel
  queue(queue_name)
  channel.default_exchange.publish(payload, :routing_key => get_queue_name(queue_name))
  channel.close
end
queue(name, channel = self.channel) click to toggle source
# File lib/rabbithole/connection.rb, line 25
def queue(name, channel = self.channel)
  channel.queue(get_queue_name(name), :durable => true)
end
session() click to toggle source
# File lib/rabbithole/connection.rb, line 29
def session
  @connection ||=
    begin
      connection = Bunny.new(configuration)
      connection.start
    end
end