lib/rabbit-utils/create-app-connection.js
function createAppConnection (app, url, socketOptions) {
  assert(!app.connection, 'Cannot create connection if it already exists')

  return co(function * () {
    const conn =
      app.connection =
        yield amqplib.connect(url, socketOptions)

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

    return conn
  })
}
function createAppConnection (app, url, socketOptions) {
  assert(!app.connection, 'Cannot create connection if it already exists')

  return co(function * () {
    const conn =
      app.connection =
        yield amqplib.connect(url, socketOptions)

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

    return conn
  })
}
Create a RabbitMQ connection
@param  {Application} app        coworkers application
@param  {String} url             connection url
@param  {Object} [socketOptions] connection socket options
@return {Promise}                connection promise