连接到JanusGraph使用gremlin-go时出现连接被拒绝的错误。

huangapple go评论67阅读模式
英文:

Connection refused when connecting to JanusGraph using gremlin-go

问题

我无法连接到JanusGraph,通过gremlin-go连接被拒绝。根据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() {
	// 创建与服务器的连接。
	driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection("ws://localhost:8182/gremlin")
	// 处理错误
	if err != nil {
		fmt.Println(err)
		return
	}
	// 清理
	defer driverRemoteConnection.Close()

	// 创建图遍历
	g := gremlingo.Traversal_().WithRemote(driverRemoteConnection)

	// 执行遍历
	result, err := g.V().Count().ToList()
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(result[0].GetString())

	// 使用Iterate()将具有属性的顶点添加到图中
	_, promise, _ := g.AddV("gremlin").Property("language", "go").Iterate()

	// 返回的promise是一个go通道,用于等待所有提交的步骤完成执行并返回错误。
	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 gremlin tinkerpop/gremlin-server通过gremlin服务器可以正常工作。我缺少哪些配置?

英文:

I fail to connect to JanusGraph via gremlin-go - connection is refused. According to gremlin-go documentation, it allows to connect to any graph database that supports TinkerPop3, e.g. JanusGraph, Neo4J etc..

Starting JanusGraph:

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

This spins up JanusGraph container at port 8182.

Executing main.go with following content (some example from gremlin-go documentation):

package main

import (
	&quot;fmt&quot;
	&quot;github.com/apache/tinkerpop/gremlin-go/v3/driver&quot;
)

func main() {
	// Creating the connection to the server.
	driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection(&quot;ws://localhost:8182/gremlin&quot;)
	// 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(&quot;gremlin&quot;).Property(&quot;language&quot;, &quot;go&quot;).Iterate()

	// The returned promised is a go channel to wait for all submitted steps to finish execution and return error.
	err = &lt;-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())
}

This results in connection refused:

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: &#39;dial tcp [::1]:8182: connect: connection refused&#39;
dial tcp [::1]:8182: connect: connection refused

However, using gremlin server via docker run --rm -it -p 8182:8182 --name gremlin tinkerpop/gremlin-server works fine.
What configuration am I missing?

答案1

得分: 1

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

英文:

Open port on localhost via docker run --rm -it -p 8182:8182 --name janusgraph janusgraph/janusgraph:latest.

huangapple
  • 本文由 发表于 2022年5月16日 17:18:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/72256833.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定