Using a separate admin '/' vhost login
and shutting down more cleanly.
This commit is contained in:
parent
0e5566367c
commit
2bf7d416e2
@ -17,20 +17,29 @@ class Sylvilagus::Ch03::LogListeners
|
||||
|
||||
def main
|
||||
factory = ConnectionFactory.new
|
||||
factory.uri = ENV.fetch('SYLVILAGUS_AMQP_URI')
|
||||
conn = factory.new_connection
|
||||
amqp_uri = ENV.fetch('SYLVILAGUS_ROOT_ADMIN_AMQP_URI')
|
||||
factory.uri = amqp_uri
|
||||
puts "Getting connection for #{amqp_uri.inspect}..."
|
||||
@conn = factory.new_connection
|
||||
|
||||
trap :INT do
|
||||
conn.close
|
||||
begin
|
||||
@conn.close
|
||||
exit 1
|
||||
rescue NativeException
|
||||
exit 2
|
||||
end
|
||||
end
|
||||
|
||||
channel = conn.create_channel
|
||||
puts 'Getting channel...'
|
||||
channel = @conn.create_channel
|
||||
|
||||
puts 'Declaring queues...'
|
||||
errors_queue = channel.queue_declare.get_queue
|
||||
warnings_queue = channel.queue_declare.get_queue
|
||||
info_queue = channel.queue_declare.get_queue
|
||||
|
||||
puts "Binding queues to 'amq.rabbitmq.log' exchange..."
|
||||
channel.queue_bind(errors_queue, 'amq.rabbitmq.log', 'error')
|
||||
channel.queue_bind(warnings_queue, 'amq.rabbitmq.log', 'warning')
|
||||
channel.queue_bind(info_queue, 'amq.rabbitmq.log', 'info')
|
||||
@ -39,6 +48,7 @@ class Sylvilagus::Ch03::LogListeners
|
||||
warnings_consumer = LogConsumer.new(channel)
|
||||
info_consumer = LogConsumer.new(channel)
|
||||
|
||||
puts 'Setting up consumers...'
|
||||
channel.basic_consume(errors_queue, false, errors_consumer)
|
||||
channel.basic_consume(warnings_queue, false, warnings_consumer)
|
||||
channel.basic_consume(info_queue, false, info_consumer)
|
||||
@ -47,7 +57,10 @@ class Sylvilagus::Ch03::LogListeners
|
||||
sleep 1
|
||||
end
|
||||
ensure
|
||||
conn.close
|
||||
begin
|
||||
@conn.close if @conn
|
||||
rescue NativeException
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user