Reputation: 316
I'm having one CentOS machine over network. In which I tried to connect Cassandra using NodeJS through express-cassandra node_module. And when I start my application it gives me following error log.
0|app | 2018-03-07T14:49:21.329 ERROR cassandra 4456 {
NoHostAvailableError: All host(s) tried for query failed. First host tried,
127.0.0.1:9160: OperationTimedOutError: The host 127.0.0.1:9160 did not
reply before timeout 12000 ms. See innerErrors.
0|app | at whilstEnded
(/opt/cisco/sprint5_node/node_modules/cassandra-driver/lib/control-
connection.js:231:25)
0|app | at next (/opt/cisco/sprint5_node/node_modules/cassandra-
driver/lib/utils.js:842:14)
0|app | at borrowConnectionCallback
(/opt/cisco/sprint5_node/node_modules/cassandra-driver/lib/control-
connection.js:226:9)
0|app | at HostConnectionPool.create.err
(/opt/cisco/sprint5_node/node_modules/cassandra-driver/lib/host-connection-
pool.js:71:16)
0|app | at Object.onceWrapper (events.js:315:30)
0|app | at emitOne (events.js:116:13)
0|app | at HostConnectionPool.emit (events.js:211:7)
0|app | at whilstEnded
(/opt/cisco/sprint5_node/node_modules/cassandra-driver/lib/host-connection-
pool.js:173:23)
0|app | at next (/opt/cisco/sprint5_node/node_modules/cassandra-
driver/lib/utils.js:839:14)
0|app | at HostConnectionPool.<anonymous>
(/opt/cisco/sprint5_node/node_modules/cassandra-driver/lib/utils.js:851:9)
0|app | at Object.onceWrapper (events.js:315:30)
0|app | at emitOne (events.js:121:20)
0|app | at HostConnectionPool.emit (events.js:211:7)
0|app | at attemptOpenCallback
(/opt/cisco/sprint5_node/node_modules/cassandra-driver/lib/host-connection-
pool.js:223:21)
0|app | at Connection.errorConnecting
(/opt/cisco/sprint5_node/node_modules/cassandra-
driver/lib/connection.js:225:3)
0|app | at Socket.socketError
(/opt/cisco/sprint5_node/node_modules/cassandra-
driver/lib/connection.js:146:10)
0|app | name: 'NoHostAvailableError',
0|app | info: 'Represents an error when a query cannot be performed
because no host is available or could be reached by the driver.',
I tried to change rpc_address, listen_address with help of other links, but still facing issue.
This is code to bind models
cassandra_model.setDirectory(path.resolve() + '/app' + '/models')
.bind({
clientOptions: {
contactPoints: [config.cassandra.ip],
protocolOptions: { port: config.cassandra.port },
keyspace: config.cassandra.keyspace,
queryOptions: { consistency: cassandra_model.consistencies.one },
socketOptions: { readTimeout: 0 }
},
ormOptions: {
defaultReplicationStrategy: {
class: 'SimpleStrategy',
replication_factor: 1
},
migration: 'alter',
createKeyspace: true
}
}, function onError(err) {
cassandra_model.timeuuid()
if (err) {
logger.error(err);
}
else {
logger.info('Cassandra_model initialized!');
}
});
above code works fine. Now I want to connect to keyspace without binding of models. so tried following code.
var ExpressCassandra = require('express-cassandra');
var models = ExpressCassandra.createClient({
clientOptions: {
contactPoints: [config.cassandra.ip],
protocolOptions: { port: 9042 },
keyspace: config.cassandra.keyspace,
queryOptions: { consistency: ExpressCassandra.consistencies.one }
},
ormOptions: {
defaultReplicationStrategy: {
class: 'SimpleStrategy',
replication_factor: 1
},
migration: 'safe',
}
}, function onError(err) {
cassandra_model.timeuuid()
if (err) {
logger.error(err);
}
else {
logger.info('Cassandra initialized!');
}
});
but I'm not able to connect to cassandra. Anything I'm doing wrong over here?
Upvotes: 0
Views: 1736