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

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

Connection refused when connecting to JanusGraph using gremlin-go

问题

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

启动JanusGraph:

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

这将在端口8182上启动JanusGraph容器。

执行以下内容的main.go(来自gremlin-go文档的示例):

  1. package main
  2. import (
  3. "fmt"
  4. "github.com/apache/tinkerpop/gremlin-go/v3/driver"
  5. )
  6. func main() {
  7. // 创建与服务器的连接。
  8. driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection("ws://localhost:8182/gremlin")
  9. // 处理错误
  10. if err != nil {
  11. fmt.Println(err)
  12. return
  13. }
  14. // 清理
  15. defer driverRemoteConnection.Close()
  16. // 创建图遍历
  17. g := gremlingo.Traversal_().WithRemote(driverRemoteConnection)
  18. // 执行遍历
  19. result, err := g.V().Count().ToList()
  20. if err != nil {
  21. fmt.Println(err)
  22. return
  23. }
  24. fmt.Println(result[0].GetString())
  25. // 使用Iterate()将具有属性的顶点添加到图中
  26. _, promise, _ := g.AddV("gremlin").Property("language", "go").Iterate()
  27. // 返回的promise是一个go通道,用于等待所有提交的步骤完成执行并返回错误。
  28. err = <-promise
  29. if err != nil {
  30. fmt.Println(err)
  31. return
  32. }
  33. result, err = g.V().Count().ToList()
  34. if err != nil {
  35. fmt.Println(err)
  36. return
  37. }
  38. fmt.Println(result[0].GetString())
  39. }

这导致连接被拒绝:

  1. 2022/05/16 11:04:46 Connecting.
  2. 2022/05/16 11:04:46 Failed to connect, connection is closed.
  3. 2022/05/16 11:04:46 Error occurred during operation NewDriverRemoteConnection: 'dial tcp [::1]:8182: connect: connection refused'
  4. 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:

  1. 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):

  1. package main
  2. import (
  3. &quot;fmt&quot;
  4. &quot;github.com/apache/tinkerpop/gremlin-go/v3/driver&quot;
  5. )
  6. func main() {
  7. // Creating the connection to the server.
  8. driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection(&quot;ws://localhost:8182/gremlin&quot;)
  9. // Handle error
  10. if err != nil {
  11. fmt.Println(err)
  12. return
  13. }
  14. // Cleanup
  15. defer driverRemoteConnection.Close()
  16. // Creating graph traversal
  17. g := gremlingo.Traversal_().WithRemote(driverRemoteConnection)
  18. // Perform traversal
  19. result, err := g.V().Count().ToList()
  20. if err != nil {
  21. fmt.Println(err)
  22. return
  23. }
  24. fmt.Println(result[0].GetString())
  25. // Add a vertex with properties to the graph with the terminal step Iterate()
  26. _, promise, _ := g.AddV(&quot;gremlin&quot;).Property(&quot;language&quot;, &quot;go&quot;).Iterate()
  27. // The returned promised is a go channel to wait for all submitted steps to finish execution and return error.
  28. err = &lt;-promise
  29. if err != nil {
  30. fmt.Println(err)
  31. return
  32. }
  33. result, err = g.V().Count().ToList()
  34. if err != nil {
  35. fmt.Println(err)
  36. return
  37. }
  38. fmt.Println(result[0].GetString())
  39. }

This results in connection refused:

  1. 2022/05/16 11:04:46 Connecting.
  2. 2022/05/16 11:04:46 Failed to connect, connection is closed.
  3. 2022/05/16 11:04:46 Error occurred during operation NewDriverRemoteConnection: &#39;dial tcp [::1]:8182: connect: connection refused&#39;
  4. 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:

确定