title: Need only one connection with RbbitMQ for the node application, not for every publish call
body: <p>Whenever I publish new message it create one new connection. I want to have only one connection and one channel for all the publich calls.</p>
  
  <p>Read from the rabbitmq website:
  Some applications need multiple connections to an AMQP broker. However, it is undesirable to keep many TCP connections open at the same time because doing so consumes system resources and makes it more difficult to configure firewalls. AMQP 0-9-1 connections are multiplexed with channels that can be thought of as "lightweight connections that share a single TCP connection".</p>
  
  <p>But how???
  Here is my Code:</p>
  
  <p>Channel.js</p>
  
  <pre><code>var amqp = require('amqplib/callback_api');
  
  var url = process.env.AMQP_URL || 'amqp://guest:guest@localhost:5672';
  
  module.exports = createQueueChannel;
  
  function createQueueChannel(queue, cb) {
    console.log("connecting................");
    amqp.connect(url, onceConnected);
  
    function onceConnected(err, conn) {
      if (err) {
        console.error('Error connecting:', err.stack);
      }
      else {
        console.log('connected');
        conn.createChannel(onceChannelCreated);
      }
  
      function onceChannelCreated(err, channel) {
        if (err) {
          cb(err);
        }
        else {
          channel.assertQueue(queue, {durable: true}, onceQueueCreated);
        }
  
        function onceQueueCreated(err) {
          if (err) {
            cb(err);
          }
          else {
            cb(null, channel, conn);
          }
        }
      }
    }
  
  }
  </code></pre>
  
  <p>Publish.js</p>
  
  <pre><code>var Channel = require('./channel');
  
  var queue = 'queue';
  
  Channel(queue, function(err, channel, conn) {
    if (err) {
      console.error(err.stack);
    }
    else {
      console.log('channel and queue created');
      var work = 'Do some work';
      channel.sendToQueue(queue, encode(work), {
        persistent: true
      });
      // setImmediate(function() {
      //   channel.close();
      //   conn.close();
      // });
    }
  });
  
  
  function encode(doc) {
    return new Buffer(JSON.stringify(doc));
  }
  </code></pre>