gpt4 book ai didi

Node.js cassandra 连接超时

转载 作者:太空宇宙 更新时间:2023-11-04 02:11:47 27 4
gpt4 key购买 nike

我在使用 Node js 连接 cassandra 实例时收到超时消息 Cassandra 版本:3.9 Node 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 是提前创建的。如何避免服务器启动时出现超时异常?

最佳答案

您似乎连接到了错误的端口。Apache Cassandra native 协议(protocol)的默认端口是 9042,但看起来您正在尝试使用 7000。

https://docs.datastax.com/en/cassandra/2.1/cassandra/security/secureFireWall_r.html

尝试使用 cqlsh 进行连接。查看 cassandra.yaml 文件中的 native_transport_port 设置(默认为 9042)。

关于Node.js cassandra 连接超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41749001/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com