lib/rabbit-utils/create-app-channel.js
function createAppChannel (app, key) {
  assert(~['consumerChannel', 'publisherChannel'].indexOf(key),
    'Channel key must be "consumerChannel" or "publisherChannel"')
  assert(app.connection, 'Cannot create a channel without a connection')
  assert(!app[key], 'Channel "' + key + '" already exists')

  return co(function * () {
    const channel =
      app[key] =
        yield app.connection.createChannel()

    channel.__coworkersCloseHandler = module.exports.closeHandler.bind(null, app, key)
    channel.__coworkersErrorHandler = module.exports.errorHandler.bind(null, app, key)
    channel.once('close', channel.__coworkersCloseHandler)
    channel.once('error', channel.__coworkersErrorHandler)
    app.emit('channel:create', channel)

    // attach special event to determine if a message has been confirmed
    // this event is handled in context.js
    if (key === 'consumerChannel') {
      if (app.prefetchOpts) {
        channel.prefetch(app.prefetchOpts.count, app.prefetchOpts.global)
      }
      wrap(channel, ['ack', 'nack'], function (fn, args) {
        const message = args[0]
        assert(!message.messageAcked, 'Messages cannot be acked/nacked more than once (will close channel)')

        const ret = fn.apply(this, args)
        message.messageAcked = true
        return ret
      })
    }

    return channel
  })
}
function createAppChannel (app, key) {
  assert(~['consumerChannel', 'publisherChannel'].indexOf(key),
    'Channel key must be "consumerChannel" or "publisherChannel"')
  assert(app.connection, 'Cannot create a channel without a connection')
  assert(!app[key], 'Channel "' + key + '" already exists')

  return co(function * () {
    const channel =
      app[key] =
        yield app.connection.createChannel()

    channel.__coworkersCloseHandler = module.exports.closeHandler.bind(null, app, key)
    channel.__coworkersErrorHandler = module.exports.errorHandler.bind(null, app, key)
    channel.once('close', channel.__coworkersCloseHandler)
    channel.once('error', channel.__coworkersErrorHandler)
    app.emit('channel:create', channel)

    // attach special event to determine if a message has been confirmed
    // this event is handled in context.js
    if (key === 'consumerChannel') {
      if (app.prefetchOpts) {
        channel.prefetch(app.prefetchOpts.count, app.prefetchOpts.global)
      }
      wrap(channel, ['ack', 'nack'], function (fn, args) {
        const message = args[0]
        assert(!message.messageAcked, 'Messages cannot be acked/nacked more than once (will close channel)')

        const ret = fn.apply(this, args)
        message.messageAcked = true
        return ret
      })
    }

    return channel
  })
}
Create consumer or publisher RabbitMQ channel
@param {String} key channel key {consumer, publisher}
@return {Promise} channel promise