0

I'm using express-cassandra version 0.5.4 to connect to my hosted aws cassandra db. I am authorized to access, but no matter what I change I'm getting ECONNREFUSED

Here is the snippet for express-cassandra that's connecting, which is pretty standard right from the docs.

models.setDirectory(__dirname + '/../models').bind({ clientOptions: { contactPoints: [process.env.Cluster1Pub,process.env.Cluster2Pub,process.env.Cluster3Pub], protocolOptions: {port: 9042}, keyspace: process.env.keyspace }, ormOptions: { defaultReplicationStrategy : { class: 'NetworkTopologyStrategy', replication_factor: 3 }, dropTableOnSchemaChange: false, dontCreateKeyspace: true } },function(err) { if(err) console.log(err.message); else console.log(models.timeuuid()); });

Austin Shoecraft
  • 215
  • 1
  • 3
  • 16
  • This is a pretty common network error when trying to connect to an unopened port. Have you verified that you can hit that port from your client machine? (`nc -z process.env.Cluster1Pub 9042`, for example) – Adam Holmberg May 06 '16 at 21:33
  • I tried nc -vz ip port (just z didn't show anything) and I got connection refused. On aws I have it set to accept my ip with all traffic and all ports. – Austin Shoecraft May 06 '16 at 22:03
  • if you can't netcat or telnet to the port you have a firewall problem. Check both the OS firewall and the AWS firewall. – phact May 06 '16 at 22:13
  • is DSE running? can you hit cqlsh locally? – phact May 06 '16 at 22:13
  • It's a remote db, I just tried deploying the server and trying it out there but I have the same issue. What's DSE? – Austin Shoecraft May 06 '16 at 22:35
  • With `NetworkTopologyStrategy` you need the name of the Data Center (i.e. `DC1`) to define the replication factor as in: `DC1: 3`. – Alexis Wilke Dec 05 '18 at 17:32

2 Answers2

2

Try these settings

Change rpc_address: 0.0.0.0 broadcast_rpc_address: 1.2.3.4

Reference: "All host(s) tried for query failed" Error

Community
  • 1
  • 1
AJ Keller
  • 52
  • 5
0

If you are trying to connect to a Cassandra database sitting inside a docker container. Please expose the port when creating your database container using...

docker run -d -it -p 9042:9042 -p 9041:9041 --name <container_name> <docker_image_id>

After you have exposed the database port, then you can not connect with the database using the nodejs cassandra-driver using...

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

const client = new cassandra.Client({
  contactPoints: ['h1', 'h2'],
  localDataCenter: 'datacenter1',
  keyspace: 'ks1'
});

const query = 'SELECT name, email FROM users WHERE key = ?';

client.execute(query, [ 'someone' ])
  .then(result => console.log('User with email %s', result.rows[0].email));
yTek
  • 59
  • 1
  • 3