basho / riak-nodejs-client

The Riak client for Node.js.
Apache License 2.0
72 stars 28 forks source link

Riak nodes coming as unavailable from Node server [JIRA: CLIENTS-810] #146

Closed vikram17000 closed 8 years ago

vikram17000 commented 8 years ago

Hi - this is probably not a bug but rather a gap in my understanding but putting it here as afraid havent been able to find a way so far. Appreciate if you can provide your inputs please.

I'm trying to connect to my Riak cluster (hosted on AWS) of 3 nodes via two options - 1) Using an ejabberd server, and 2) using a Node server.

Connecting from the ejabberd server is successful after I put the hostname and port in the ejabberd configuration, but when I use a simple Node server (code below), I get the "Error: No RiakNodes available to execute command." error. Am I missing out on something here please - I can confirm that the 3 nodes are indeed up with Riak running? Note that if I dont do the client ping on the nodes, the server doesnt throw any error, so it is probably got to do with how pings are handled. The same server (without the ping) gives an ECONNREFUSED error if one of the nodes are brought down. So clearly the connection is going through but not the ping.

Apologize if am missing out on something basic here ... even the firewall settings for the Riak nodes have been set to all inbound, so it is not a case of the ejabberd server having access but not the Node server.

var async = require('async'); var assert = require('assert'); var logger = require('winston'); var Riak = require('basho-riak-client');

logger.remove(logger.transports.Console); logger.add(logger.transports.Console, { level : 'debug', colorize : true, timestamp : true });

var nodes = [ 'ip-xx-xx-xx-xx:8087', 'ip-xx-xx-xx-xx:8087', 'ip-xx-xx-xx-xx:8087' ];

var client = new Riak.Client(nodes, function (err, c) { logger.info('Now inside Riak.Client');

// NB: at this point the client is fully initialized, and
// 'client' and 'c' are the same object

});

client.ping(function (err, rslt) { logger.info('Now entered client.ping'); if (err) { logger.info('There is an error encountered in client.ping'); throw new Error(err); } else { // On success, ping returns true logger.info('client.ping has resulted in success!'); assert(rslt === true); } });

lukebakken commented 8 years ago

Please give this code a try and re-open this issue if it does not resolve your issue. Note that interaction with the Riak.Client object must come in the callback:

var async = require('async');
var assert = require('assert');
var logger = require('winston');
var Riak = require('basho-riak-client');

logger.remove(logger.transports.Console);
logger.add(logger.transports.Console, {
    level : 'debug',
    colorize : true,
    timestamp : true
});

var nodes = [
    'ip-xx-xx-xx-xx:8087',
    'ip-xx-xx-xx-xx:8087',
    'ip-xx-xx-xx-xx:8087'
];

var unused = new Riak.Client(nodes, function (err, client) {
    logger.info('Now inside Riak.Client');
    client.ping(function (err, rslt) {
        logger.info('Now entered client.ping');
        if (err) {
            logger.info('There is an error encountered in client.ping');
            throw new Error(err);
        } else {
            // On success, ping returns true
            logger.info('client.ping has resulted in success!');
            assert(rslt === true);
        }
        client.stop(function () {
            logger.info('client is stopped');
            process.exit();
        });
    });
});
vikram17000 commented 8 years ago

Thanks very much Luke... works perfectly... many thanks again for your help!

lukebakken commented 8 years ago

@vikram17000 - thank you for letting me know, and always feel free to open an issue if you have a question, issue, or suggestion for the Riak Node.js Client.

Basho-JIRA commented 7 years ago

Fixed, or closed via GitHub issues.

[posted via JIRA by Alexander Moore]