Files
old-vendor-scheduler-service/app/services/amqp/amqp_service.rb
2022-03-23 05:44:42 +01:00

39 lines
761 B
Ruby

# frozen_string_literal: true
module Amqp
class AmqpService
include Singleton
def queue(queue_name, options = {})
@queue ||= {}
@queue[queue_name] ||= channel.queue queue_name, options
end
def exchange(exchange_name, exchange_type, options = {})
@exchange ||= {}
@exchange[exchange_name] ||= channel.exchange exchange_name, options.merge(type: exchange_type)
end
def default_exchange
channel.default_exchange
end
private
def channel
@channel ||= connection.create_channel
end
def connection
@connection ||= begin
Bunny.new(amqp_config).tap do |conn|
conn.start
end
end
end
def amqp_config
AppConfig.amqp
end
end
end