Initial commit
This commit is contained in:
38
app/services/amqp/amqp_service.rb
Normal file
38
app/services/amqp/amqp_service.rb
Normal file
@@ -0,0 +1,38 @@
|
||||
# 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
|
||||
Reference in New Issue
Block a user