node.jscassandracassandra-3.0scyllacassandra-driver

How to connect Node.js app properly to Cassandra node?


I have two Cassandra nodes hosted on two IPs. Now, when I am connecting to one of those nodes via cassandra-driver in Node.js from Windows, I am getting 'connection timed out' and 'host unreachable' kind of errors. However, I am able to connect to those nodes via CQLSH from outside of their network.

Am I doing something wrong? Here is the sample code.

var cassandra = require('cassandra-driver');

var uuid = require('uuid')
var client = new cassandra.Client({ contactPoints: ['(PUBLIC IP Here) X.X.X.X:9042'], localDataCenter: 'datacenter1', keyspace: 'ksks' });

function getAllPersons() {
    var query = 'SELECT * FROM person';
    return new Promise((resolve, reject) => {
        client.connect(function (err) {
            if (err) return console.error(err);
            else {
                client.execute(query, function (err, result) {
                    if(err)  {
                        reject([])
                    }
                    else {
                        if(result.rows.length) {
                            resolve(result.rows);
                        }
                        else {}
                            reject([])
                    }
                });
            }
        });
     });
}

In the cassandra.yaml, I have these values:

listen_address: 10.0.0.4
native_transport_port: 9042
rpc_address: 10.0.0.4
rpc_port: 9160
api_port: 10000
api_address: 10.0.0.4

What do I need to change? The nodes are working fine and can CQLSH to each other (from remote networks as well).


Solution

  • If you are using a public IP to access the cluster remotely your configurations are not correct.

    This table might help you figure out the correct IPs in the scylla.yaml:

    https://docs.scylladb.com/operating-scylla/procedures/cluster-management/ec2_dc/#ec2-configuration-table

    Do NOT use Ec2Snitch unless you are on AWS. The table is just a reference.