通过 Websocket 连接到 JanusGraph

Connecting to JanusGraph over Websocket

我目前是 运行 JanusGraph (0.1.1),我 运行 在尝试通过 Websocket 连接时遇到了一些困难 - 不过请注意,Gremlin 控制台工作正常。

我使用 Nodejs 作为客户端,并且尝试了所有可用的模块。我可以确认我确实通过了 SSL 安全(提供证书本身或使用 rejectUnauthorized 选项)。然后,根据客户端库,我能够测试连接是否确实打开但似乎没有查询通过。我得到的唯一线索是 'gremlin' 模块响应错误 401 - 使用与 http 端点(有效)相同的凭据。

谁能指导我通过正确的方式实现这个 Websocket 连接?我用两个不同的库附上了两个例子。

// With Gremlin module
const Gremlin = require("gremlin");
const client = Gremlin.createClient(<my-port>, '<my-url>', { 
  path: '/', 
  user: '<my-user>', 
  password: '<my-password>', 
  ssl: true, 
  rejectUnauthorized: false, 
  session: true,
});
client.execute('def graph=ConfiguredGraphFactory.open("test3")', { }, (err, results) => {
    if (err) {
      return console.error(err)
    }
    console.log(results);
});

// With Ws module
const WebSocket = require('ws');
var fs = require('fs');
const ws = new WebSocket('wss://<my-url>:<my-port>', {
  ca: fs.readFileSync("./ssl.cert"), // required to get passed the leaf certificate error
  extraHeaders: {
    Authorization: 'Basic ' + new Buffer('<my-user>:<my-password>').toString('base64')
  },
  perMessageDeflate: false,
  ssl: true,
  json: true,
  strictSSL: false,
  // rejectUnauthorized: false, // does not work - needs the certificate
});
ws.onopen = function (event) {
  console.log('SSL OK: ', event.target._sender._socket.authorized);
  ws.send("{'gremlin': 'def graph=ConfiguredGraphFactory.open(\"test3\");graph.addVertex(label,\"some vertex\");graph.tx().commit();'}", function(res){
    console.log(res);
    ws.close();
  });
};

issue and the root cause was fixed with this issue中也描述了此问题:SASL 参数设置不正确

此问题已在版本 2.7.0 的 Javascript 客户端中修复,因此请确保更新 package.json 以使用该版本。