class IvoryTower::Queue

Attributes

name[R]

Public Class Methods

new(name) click to toggle source
# File lib/ivory_tower/queue.rb, line 5
def initialize(name)
  @bunny_queue = IvoryTower::BunnyFactory.queue name
end

Public Instance Methods

close_connection() click to toggle source
# File lib/ivory_tower/queue.rb, line 40
def close_connection
  unless connection.status == :closed
    connection.close
  end
end
consume(&block) click to toggle source
# File lib/ivory_tower/queue.rb, line 9
def consume(&block)
  bunny_queue.subscribe subscribe_options do |delivery_info, properties, body|
    message = Hashie::Mash.new(JSON.parse(body))
    block.call(message)
    channel.ack delivery_info.delivery_tag
  end
ensure
  close_connection if subscribe_options[:block]
end
empty!() click to toggle source
# File lib/ivory_tower/queue.rb, line 32
def empty!
  bunny_queue.purge
end
open?() click to toggle source
# File lib/ivory_tower/queue.rb, line 36
def open?
  connection.status == :open
end
produce(message) click to toggle source
# File lib/ivory_tower/queue.rb, line 19
def produce(message)
  bunny_queue.publish(message.to_json)
  close_connection
end
size() click to toggle source
# File lib/ivory_tower/queue.rb, line 24
def size
  bunny_queue.message_count
end
subscribe_options=(changes) click to toggle source
# File lib/ivory_tower/queue.rb, line 28
def subscribe_options=(changes)
  subscribe_options.merge!(changes)
end

Private Instance Methods

bunny_queue() click to toggle source
# File lib/ivory_tower/queue.rb, line 52
def bunny_queue
  @bunny_queue
end
channel() click to toggle source
# File lib/ivory_tower/queue.rb, line 56
def channel
  @bunny_queue.channel
end
connection() click to toggle source
# File lib/ivory_tower/queue.rb, line 60
def connection
  channel.connection
end
subscribe_options() click to toggle source
# File lib/ivory_tower/queue.rb, line 48
def subscribe_options
  @subscribe_options ||= {manual_ack: true, block: true}
end