title: Node Js / Typescript - AMQP Consumer
body: <p>I am trying my hand at node.js/typescript for the first time and having a bit of trouble making a consumer for a rabbit queue.</p>
  
  <p>Code:</p>
  
  <pre><code>let amqp = require('amqp');
  
  let connection = amqp.createConnection({url: "amqp://" + RABBITMQ_USER + ":" + RABBITMQ_PASSWORD + "@" + RABBITMQ_HOST + ":" + RABBITMQ_PORT + RABBITMQ_VHOST});
  
  connection.on('ready', function() {
      connection.exchange(RABBITMQ_WORKER_EXCHANGE, function (exchange) {
          connection.queue(RABBITMQ_QUEUE, function (queue) {
              queue.bind(exchange, function() {
                  queue.publish(function (message) {
                      console.log('subscribed to queue');
                      let encoded_payload = unescape(message.data);
                      let payload = JSON.parse(encoded_payload);
                      console.log('Received a message:');
                      console.log(payload);
                  })
              })
          })
      })
  })
  </code></pre>
  
  <p>It seems to connect to the amqp server and throws no errors but it just sits there and doesn't consume anything. Is there a step I am missing?</p>
  
  <p>Any help would be greatly appreciated,
  Thank you.</p>