Search code examples
gogremlinjanusgraphgremlin-server

Connection refused when connecting to JanusGraph using gremlin-go


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?


Solution

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