Example #1
0
exports.connect = function() {
  connection.connect();

  // FIXME: This shouldn't have to be in here. Check if upstream node-amqp
  //        fixes that connection issue.
  createCallback(connection);
};
Example #2
0
function Connection(connectionArgs, options) {
    var self = this;

    amqp.Connection.apply(this, arguments);

    if (options) {
        this.resource = options.resource;
        this.log = options.log;
    }

    this.connected = false;
    this.connecting = false;
    this.reconnectionInterval = null;
    this.reconnectTimeout = null;


    self.on('ready', function () {
        self.log.info('AMQP Ready');
        self.connecting = false;
        self.connected = true;

        clearTimeout(self.reconnectTimeout);
        clearInterval(self.reconnectionInterval);
        self.reconnectTimeout = null;
        self.reconnectionInterval = null;

    });

    self.on('error', function (e) {
        self.connecting = false;
        self.log.error(e, 'AMQP connection error');

        clearTimeout(self.reconnectTimeout);
        clearInterval(self.reconnectionInterval);
        self.reconnectTimeout = null;
        self.reconnectionInterval = null;

        self.reconnectionInterval = setInterval(function () {
            self.log.info('forcing reconnect');
            self.reconnect();
        }, 5000);
    });

    self.on('close', function (e) {
        self.log.info('AMQP Connection close');
        self.connecting = false;
        self.connected = false;

        clearTimeout(self.reconnectTimeout);
        clearInterval(self.reconnectionInterval);
        self.reconnectTimeout = null;
        self.reconnectionInterval = null;

        self.reconnectionInterval = setInterval(function () {
            self.log.info('Forcing reconnect');
            self.reconnect();
        }, 5000);
    });
}
Example #3
0
exports.challenge = function(challengeId, commands, callback) {
  var sub_uuid = uuid();
  connection.publish('runCode', { challengeId: challengeId
                                , commands: commands
                                , responseQueue: queue_uuid
                                , sub_uuid: sub_uuid }, {autoDelete: true});

  workerResponse.once(sub_uuid, callback);
};