我在使用Node js连接到cassandra实例时收到超时 卡桑德拉版本:3.9 节点js:v6.9.1 我使用此驱动程序进行连接:https://github.com/datastax/nodejs-driver
这是我的代码段:
const express = require('express');
const cassandra = require('cassandra-driver');
const async = require('async');
// Constants
const PORT = 8080;
const CASSANDRA_PORT = process.env['CASSANDRA_PORT'];
const CASSANDRA_PATH = '127.0.0.1';
// App
const app = express();
app.set('view engine', 'pug');
app.set('views', './views');
var client = new cassandra.Client({contactPoints: [CASSANDRA_PATH], protocolOptions: {port: CASSANDRA_PORT}});
client.on('log', function(level, className, message, furtherInfo) {
console.log('log event: %s -- %s', level, message);
});
client.connect(function (e, m) {
console.log(e);
console.log(m);
});
错误堆栈跟踪:
log event: info -- Adding host 127.0.0.1:7000
log event: info -- Getting first connection
log event: info -- Connecting to 127.0.0.1:7000
log event: verbose -- Socket connected to 127.0.0.1:7000
log event: info -- Trying to use protocol version 4
log event: verbose -- Sending stream #0
log event: verbose -- Sent stream #0 to 127.0.0.1:7000
log event: info -- Connection to 127.0.0.1:7000 closed
log event: warning -- There was an error when trying to connect to the host 127.0.0.1
log event: warning -- Connection to 127.0.0.1:7000 could not be created: OperationTimedOutError: The host 127.0.0.1:7000 did not reply before timeout 12000 ms
log event: warning -- Connection pool to host 127.0.0.1:7000 could not be created
{ [Error: All host(s) tried for query failed. First host tried, 127.0.0.1:7000: OperationTimedOutError: The host 127.0.0.1:7000 did not reply before timeout 12000 ms. See innerErrors.]
innerErrors:
{ '127.0.0.1:7000':
{ Error: The host 127.0.0.1:7000 did not reply before timeout 12000 ms
at OperationTimedOutError.DriverError (
message: 'The host 127.0.0.1:7000 did not reply before timeout 12000 ms',
info: 'Represents a client-side error that is raised when the client did not hear back from the server within socketOptions.readTimeout' } },
info: 'Represents an error when a query cannot be performed because no host is available or could be reached by the driver.',
message: 'All host(s) tried for query failed. First host tried, 127.0.0.1:7000: OperationTimedOutError: The host 127.0.0.1:7000 did not reply before timeout 12000 ms. See innerErrors.' }
undefined
仅供参考,Keyspace是提前创建的。 如何在服务器启动期间避免此超时异常?
答案 0 :(得分:0)
看起来你正在连接错误的端口。 Apache Cassandra本机协议的默认端口是9042,但看起来您尝试使用7000。
https://docs.datastax.com/en/cassandra/2.1/cassandra/security/secureFireWall_r.html
尝试使用cqlsh进行连接。
查看cassandra.yaml文件中的native_transport_port
设置(默认为9042)。