英文:
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 (
"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())
}
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: 'dial tcp [::1]:8182: connect: connection refused'
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
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论