Skip to content

Instantly share code, notes, and snippets.

@hazeledmands
Last active August 29, 2015 14:03
Show Gist options
  • Save hazeledmands/6cf02fe96c913481768a to your computer and use it in GitHub Desktop.
Save hazeledmands/6cf02fe96c913481768a to your computer and use it in GitHub Desktop.
a simple AMQP firehose console logger
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