【问题标题】:Simple connectivity to a Gremlin DB via a Javascript Appliaction通过 Javascript 应用程序与 Gremlin DB 的简单连接
【发布时间】:2020-06-01 16:55:37
【问题描述】:

对于这样一个基本问题,我深表歉意,但我似乎无法弄清楚如何做到这一点,并且文档都非常具体。

我只是想使用 gremlin 连接到标准 Gremlin DB (Cosmos)。它在服务器上运行良好,但是当我从浏览器连接时,出现此错误:

Error: ws does not work in the browser. Browser clients must use the native WebSocket object

没有什么特别复杂的,而且错误似乎很明显。

代码如下:

     constructor() {
        var authenticator = new Gremlin.driver.auth.PlainTextSaslAuthenticator(`/dbs/${config.database}/colls/${config.collection}`, config.primaryKey);
        this.gremlin_config_options = {
            authenticator,
            traversalsource: "g",
            rejectUnauthorized: true,
            mimeType: "application/vnd.gremlin-v2.0+json"
        }

       var DriverRemoteConnection = Gremlin.driver.DriverRemoteConnection;
        this.Graph = Gremlin.structure.Graph;

        var dc = new DriverRemoteConnection(this.gremlin_websocket,this.gremlin_config_options);

        this.graph = new this.Graph();
        this.g = this.graph.traversal().withRemote(this.gremlin_websocket);
      };

当我执行以下代码时,它会在没有 Javascript 错误的情况下完成。

    constructor() {
        var authenticator = new Gremlin.driver.auth.PlainTextSaslAuthenticator(`/dbs/${config.database}/colls/${config.collection}`, config.primaryKey);
        this.gremlin_config_options = {
            authenticator,
            traversalsource: "g",
            rejectUnauthorized: true,
            mimeType: "application/vnd.gremlin-v2.0+json"
        }

        this.Graph = Gremlin.structure.Graph;

        this.gremlin_websocket = new WebSocket('ws://test_db.gremlin.cosmos.azure.com:8182/')

        this.graph = new this.Graph();
        this.g = this.graph.traversal().withRemote(this.gremlin_websocket);
      };

但是,我需要传递身份验证和收集信息(当前在身份验证器对象中)。但是WebSocket似乎不支持它,Driver Remote Connection似乎并没有原生地接受websocket。我该怎么办?

【问题讨论】:

    标签: javascript node.js azure-cosmosdb gremlin


    【解决方案1】:

    查看gremlin-browser,这是一种基于 gremlin-js v3.5.2 和 isomorphic-ws v4.0.1 版本的浏览器 JavaScript Gremlin 语言变体。使用 Azure Cosmos DB Gremlin API 2022 进行测试:)

    【讨论】:

      【解决方案2】:

      不幸的是,我不认为 gremlin-javascript 在浏览器中运行良好。我认为这是您遇到的问题。请注意,TINKERPOP-2143associated pull request 已经存在一个问题,现在已经部分完成了很长时间但尚未完成。

      【讨论】:

      • 感谢您的反馈!有什么选择:(
      • 很抱歉,我不知道解决方法。也许考虑尝试未合并的分支 - 从 cmets 看来,人们已经成功了。希望有人会尽快合并该问题。
      • 哦,哇——人们通常不会从浏览器 javascript 连接到图形数据库吗?我可以使用另一种设计模式吗?
      • 我们在两个地方进行了这次对话 - 对于那些感兴趣的人,我的回复在这里:groups.google.com/d/msg/gremlin-users/cbZMPq_UaBg/LjhCl7xaAgAJ
      • 大声笑,真的 :) 完成后我会转到线程并在此处更新。
      猜你喜欢
      • 2018-09-15
      • 2014-12-08
      • 2015-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-04
      相关资源
      最近更新 更多