【问题标题】:Node.js cassandra connection timeoutNode.js cassandra 连接超时
【发布时间】:2017-01-20 18:58:18
【问题描述】:

我在使用 Node js 连接到 cassandra 实例时收到超时 卡桑德拉版本:3.9 节点js:v6.9.1 我正在使用此驱动程序进行连接:https://github.com/datastax/nodejs-driver

这是我的代码 sn-p:

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 是预先创建的。 服务器启动时如何避免出现这个超时异常?

【问题讨论】:

    标签: node.js cassandra


    【解决方案1】:

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

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

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

    【讨论】:

    • 谢谢,9042 端口的建立帮助了我的连接!
    猜你喜欢
    • 2023-04-10
    • 2019-03-14
    • 2018-07-15
    • 2017-07-19
    • 1970-01-01
    • 2020-11-30
    • 2014-06-12
    • 2016-02-27
    • 1970-01-01
    相关资源
    最近更新 更多