登录
首页 >  Golang >  Go问答

遇到连接拒绝问题时如何用 gremlin-go 连接到 JanusGraph

来源:stackoverflow

时间:2024-02-17 20:45:23 221浏览 收藏

对于一个Golang开发者来说,牢固扎实的基础是十分重要的,golang学习网就来带大家一点点的掌握基础知识点。今天本篇文章带大家了解《遇到连接拒绝问题时如何用 gremlin-go 连接到 JanusGraph》,主要介绍了,希望对大家的知识积累有所帮助,快点收藏起来吧,否则需要时就找不到了!

问题内容

我无法通过 gremlin-go 连接到 janusgraph - 连接被拒绝。根据 gremlin-go 文档,它允许连接到任何支持 tinkerpop3 的图形数据库,例如janusgraph、neo4j 等.

启动 janusgraph:

docker run --name janusgraph-default janusgraph/janusgraph:latest

这会在端口 8182 处启动 janusgraph 容器。

使用以下内容执行 main.go (gremlin-go 文档中的一些示例):

package main

import (
    "fmt"
    "github.com/apache/tinkerpop/gremlin-go/v3/driver"
)

func main() {
    // creating the connection to the server.
    driverremoteconnection, err := gremlingo.newdriverremoteconnection("ws://localhost:8182/gremlin")
    // handle error
    if err != nil {
        fmt.println(err)
        return
    }
    // cleanup
    defer driverremoteconnection.close()

    // creating graph traversal
    g := gremlingo.traversal_().withremote(driverremoteconnection)

    // perform traversal
    result, err := g.v().count().tolist()
    if err != nil {
        fmt.println(err)
        return
    }
    fmt.println(result[0].getstring())

    // add a vertex with properties to the graph with the terminal step iterate()
    _, promise, _ := g.addv("gremlin").property("language", "go").iterate()

    // the returned promised is a go channel to wait for all submitted steps to finish execution and return error.
    err = <-promise
    if err != nil {
        fmt.println(err)
        return
    }

    result, err = g.v().count().tolist()
        if err != nil {
                fmt.println(err)
                return
        }
        fmt.println(result[0].getstring())
}

这会导致连接被拒绝:

2022/05/16 11:04:46 Connecting.
2022/05/16 11:04:46 Failed to connect, connection is closed.
2022/05/16 11:04:46 Error occurred during operation NewDriverRemoteConnection: 'dial tcp [::1]:8182: connect: connection refused'
dial tcp [::1]:8182: connect: connection refused

但是,通过 docker run --rm -it -p 8182:8182 --name gremlintinkerpop/gremlin-server 使用 gremlin 服务器可以正常工作。 我缺少什么配置?


正确答案


通过 docker run --rm -it -p 8182:8182 --name janusgraph janusgraph/janusgraph:latest 在本地主机上打开端口。

好了,本文到此结束,带大家了解了《遇到连接拒绝问题时如何用 gremlin-go 连接到 JanusGraph》,希望本文对你有所帮助!关注golang学习网公众号,给大家分享更多Golang知识!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>