-console.log "Starting Node.js faye..."
+console.log "=> Booting Node.js faye..."
 
 # Read the environment variable
 global.app_env = process.env.NODE_ENV || "development"

# Start listening to the faye server port.
faye.listen config.faye.port

console.log "Started Node.js faye server on port #{config.faye.port}"

# Get the faye client
client = faye.getClient()

  user: config.rabbit.user
  pass: config.rabbit.pass


handle_queue = (queue) ->
  queue.bind "#"
  queue.subscribe { ack: false }, (message, headers, deliveryInfo) ->
    client.publish message.channel, message.data

init_queue = ->
  connection.queue "faye", { passive: true }, (queue) ->
    handle_queue(queue)

# When AMQP connection is ready, start subscribing to the faye queue.
connection.on "ready", ->
  try
    init_queue()
  catch
    console.log "cloud not connect to [faye] queue... retrying in 10 seconds..."
    console.log "reload your web page to get the rails server to create the queue."
    setTimeout ->
      init_queue()
    , 10000
