使用节点流从cassandra二进制协议获得响应

时间:2014-02-17 05:12:37

标签: node.js stream binary cassandra

试图了解有关流和cassandra的更多信息,因此我想尝试二进制协议。我甚至无法做出回应。

var net = require('net');
var util = require('util');
var stream = require('stream');

var session;
session = net.connect({ port: 9160 }, function () {
  console.log('connected');

  var header = new Buffer([ 0x01, 0x00, 0x01, 0x01 ]);
  var length = new Buffer(4);
  var body = new Buffer("{'CQL_VERSION':'3.0.0'}", 'utf8');
  length.writeUInt32BE(body.length, 0);

  session.write(header);
  session.write(length);
  session.write(body);

  setTimeout(function () { session.end(); }, 5000);
});

session.on('error', function (err) {
  console.log(err);
});

var client = new (stream.Writable);

client._write = function (chunk, _, next) {
  console.log('response received');
  next();
};

session.pipe(client);

程序运行5秒钟,几乎立即打印“已连接”,但可写流从不接收来自数据库的内容。任何帮助将不胜感激!


我正在处理这个documentation for the binary protocolthis guide to node streams

Cassandra正在运行,版本为2.0.5

1 个答案:

答案 0 :(得分:0)

9160是Thrift的港口。您是否使用端口9042尝试了代码?