Last active
August 29, 2015 14:03
-
-
Save hazeledmands/6cf02fe96c913481768a to your computer and use it in GitHub Desktop.
a simple AMQP firehose console logger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
amqplib = require 'amqplib' | |
exec = require('child_process').exec | |
child = exec('rabbitmqctl trace_on') | |
child.stdout.pipe process.stdout | |
child.stderr.pipe process.stderr | |
connection = null | |
channel = null | |
handler = (msg) -> | |
msg.content = msg.content.toString 'utf8' | |
console.log JSON.stringify msg, null, ' ' | |
amqplib.connect("amqp://guest:guest@localhost:5672") | |
.then (conn) -> connection = conn | |
.then -> connection.createChannel() | |
.then (ch) -> channel = ch | |
.then -> | |
channel.assertQueue 'trace', durable: false | |
.then -> | |
channel.bindQueue 'trace', 'amq.rabbitmq.trace', '#' | |
.then -> | |
channel.consume 'trace', handler, noAck: on | |
.then (-> console.log 'Tracing all rabbitmq events'), (err) -> | |
console.error err.stack | |
process.on 'SIGTERM', -> | |
connection.close().then -> | |
process.exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment