Initial commit
This commit is contained in:
62
lib/peatio/amqp/config.rb
Normal file
62
lib/peatio/amqp/config.rb
Normal file
@@ -0,0 +1,62 @@
|
||||
# encoding: UTF-8
|
||||
# frozen_string_literal: true
|
||||
|
||||
module AMQP
|
||||
class Config
|
||||
class <<self
|
||||
def data
|
||||
@data ||= Hashie::Mash.new(
|
||||
YAML.safe_load(
|
||||
ERB.new(File.read(Rails.root.join('config', 'amqp.yml'))).result
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
def connect
|
||||
data[:connect]
|
||||
end
|
||||
|
||||
def binding_exchange_id(id)
|
||||
data[:binding][id][:exchange]
|
||||
end
|
||||
|
||||
def binding_exchange(id)
|
||||
eid = binding_exchange_id(id)
|
||||
eid && exchange(eid)
|
||||
end
|
||||
|
||||
def binding_queue(id)
|
||||
queue data[:binding][id][:queue]
|
||||
end
|
||||
|
||||
def binding_worker(id)
|
||||
::Workers::AMQP.const_get(id.to_s.camelize).new
|
||||
end
|
||||
|
||||
def routing_key(id)
|
||||
binding_queue(id).first
|
||||
end
|
||||
|
||||
def topics(id)
|
||||
data[:binding][id][:topics].split(',')
|
||||
end
|
||||
|
||||
def channel(id)
|
||||
(data[:channel] && data[:channel][id]) || {}
|
||||
end
|
||||
|
||||
def queue(id)
|
||||
name = data[:queue][id][:name]
|
||||
settings = { durable: data[:queue][id][:durable] }
|
||||
[name, settings]
|
||||
end
|
||||
|
||||
def exchange(id)
|
||||
type = data[:exchange][id][:type]
|
||||
name = data[:exchange][id][:name]
|
||||
[type, name]
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user