2017-01-19 18 views
1

私はノードのjs カサンドラのバージョンを使用してカサンドラインスタンスへの接続にタイムアウトを受けています:3.9 ノードJS:v6.9.1 私はこのドライバを使用して接続しています:https://github.com/datastax/nodejs-driverここNode.jsのカサンドラ接続タイムアウト

私のコードスニペットです:

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 

はFYI、キースペースが作成されますあらかじめ。 サーバの起動中にこのタイムアウト例外を回避するにはどうすればよいですか?

答えて

0

間違ったポートに接続しているようです。 のApache Cassandraのネイティブプロトコルのデフォルトのポートは9042ですが、それはあなたが7000

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

がcqlshを使用して接続してみてください使用しようとしているに見えます。 cassandra.yamlファイル(デフォルトでは9042)のnative_transport_portの設定を見てください。

+0

ありがとう、9042ポートの確立は接続で私を助けました! –

関連する問題