Sha256: 913da830bd1347d08a2b926b572dcf29b4c7fd83c26349f27ae35f0086406e31
Contents?: true
Size: 1.03 KB
Versions: 4
Compression:
Stored size: 1.03 KB
Contents
# frozen_string_literal: true require 'bunny' module Totoro class BaseQueue class <<self def config @config ||= Totoro::Config.new end def connection @connection ||= Bunny.new(config.connect).tap(&:start) end def channel @channel ||= connection.create_channel end def exchange @exchange ||= channel.default_exchange end # enqueue = publish to direct exchange def enqueue(id, payload) queue = channel.queue(*config.queue(id)) payload = JSON.dump payload exchange.publish(payload, routing_key: queue.name) Rails.logger.info "send message to #{queue.name}" STDOUT.flush end def subscribe(id) queue = channel.queue(*config.queue(id)) queue.subscribe do |delivery_info, metadata, payload| yield(delivery_info, metadata, payload) end end def get_worker(worker_class) ::Worker.const_get(worker_class.to_s.camelize).new end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
totoro-0.4.1 | lib/totoro/base_queue.rb |
totoro-0.4.0 | lib/totoro/base_queue.rb |
totoro-0.2.9 | lib/totoro/base_queue.rb |
totoro-0.2.8 | lib/totoro/base_queue.rb |