Goofing around with log consumers
although it would appear the logging exchange doesn't exist on all vhosts (???)
This commit is contained in:
parent
351a7dc5ba
commit
9e0e2ab567
4
sylvilagus/jruby/lib/sylvilagus/ch03.rb
Normal file
4
sylvilagus/jruby/lib/sylvilagus/ch03.rb
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
module Sylvilagus
|
||||||
|
module Ch03
|
||||||
|
end
|
||||||
|
end
|
56
sylvilagus/jruby/lib/sylvilagus/ch03/log_listeners.rb
Normal file
56
sylvilagus/jruby/lib/sylvilagus/ch03/log_listeners.rb
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
require 'sylvilagus/init'
|
||||||
|
require 'sylvilagus/ch03'
|
||||||
|
|
||||||
|
require 'rabbitmq-client.jar'
|
||||||
|
import com.rabbitmq.client.ConnectionFactory
|
||||||
|
import com.rabbitmq.client.DefaultConsumer
|
||||||
|
import org.jruby.RubyString
|
||||||
|
|
||||||
|
class Sylvilagus::Ch03::LogListeners
|
||||||
|
class LogConsumer < DefaultConsumer
|
||||||
|
def handleDelivery(consumer_tag, envelope, properties, body)
|
||||||
|
body_string = RubyString.bytes_to_string(body)
|
||||||
|
puts "#{level}: #{body_string}"
|
||||||
|
channel.basic_ack(envelope.delivery_tag, false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def main
|
||||||
|
factory = ConnectionFactory.new
|
||||||
|
factory.uri = ENV.fetch('SYLVILAGUS_AMQP_URI')
|
||||||
|
conn = factory.new_connection
|
||||||
|
|
||||||
|
trap :INT do
|
||||||
|
conn.close
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
|
||||||
|
channel = conn.create_channel
|
||||||
|
|
||||||
|
errors_queue = channel.queue_declare.get_queue
|
||||||
|
warnings_queue = channel.queue_declare.get_queue
|
||||||
|
info_queue = channel.queue_declare.get_queue
|
||||||
|
|
||||||
|
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')
|
||||||
|
|
||||||
|
errors_consumer = LogConsumer.new(channel)
|
||||||
|
warnings_consumer = LogConsumer.new(channel)
|
||||||
|
info_consumer = LogConsumer.new(channel)
|
||||||
|
|
||||||
|
channel.basic_consume(errors_queue, false, errors_consumer)
|
||||||
|
channel.basic_consume(warnings_queue, false, warnings_consumer)
|
||||||
|
channel.basic_consume(info_queue, false, info_consumer)
|
||||||
|
|
||||||
|
loop do
|
||||||
|
sleep 1
|
||||||
|
end
|
||||||
|
ensure
|
||||||
|
conn.close
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if $0 == __FILE__
|
||||||
|
Sylvilagus::Ch03::LogListeners.new.main
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user