northwesternmutual / grammes

A Go package built to communicate with Apache TinkerPop™ Graph computing framework using Gremlin; a graph traversal language used by graph databases such as JanusGraph®, MS Cosmos DB, AWS Neptune, and DataStax® Enterprise Graph.
Apache License 2.0
125 stars 45 forks source link

Connection to Neptune #22

Closed softngineer closed 4 years ago

softngineer commented 4 years ago

When I try to connect to Neptune using the example main.go function:

go run main.go -h "ws://<ip_of_neptune_endpoint>:8182"

the neptune ip / dns is the cluster endpoint provided when creating a neptune cluster on aws.

I get the following:

FATAL   grammes/main.go:55  Couldn't create client  {"error": "unexpected EOF"}
main.main
    /app/gremlin/go-clients/grammes/main.go:55
runtime.main
    /usr/local/go/src/runtime/proc.go:203

what am I doing wrong.

Here is the main function also provided in the example:

package main

import (
    "encoding/json"
    "flag"
    "fmt"

    "go.uber.org/zap"

    "github.com/northwesternmutual/grammes"
    "github.com/northwesternmutual/grammes/examples/exampleutil"
)

var (
    // addr is used for holding the connection IP address.
    // for example this could be, "ws://127.0.0.1:8182"
    addr string
)

func main() {
    flag.StringVar(&addr, "h", "", "Connection IP")
    flag.Parse()

    logger := exampleutil.SetupLogger()
    defer logger.Sync()

    if addr == "" {
        logger.Fatal("No host address provided. Please run: go run main.go -h <host address>")
        return
    }

    // Create a new Grammes client with a standard websocket.
    client, err := grammes.DialWithWebSocket(addr)
    if err != nil {
        logger.Fatal("Couldn't create client", zap.Error(err))
    }

    defer client.DropAll()

    // Create a graph traversal.
    g := grammes.Traversal()

    // Use the traversal to add a vertex.
    responses, err := client.ExecuteQuery(g.AddV("Intuit.cloud.monitoring.topology"))
    if err != nil {
        logger.Fatal("Error querying server", zap.Error(err))
    }

    responses, err = client.ExecuteQuery(g.V())
    if err != nil {
        logger.Fatal("Error querying server", zap.Error(err))
    }

    // Log the response from the Gremlin server.
    // This will end up being a raw JSON of a Vertex.
    for _, res := range responses {
        var result map[string]interface{}
        err := json.Unmarshal([]byte(res), &result)
        if err != nil {
            fmt.Println(err)
        }

        fmt.Println(result)
    }
}

Is this supposed to only connect locally, or in tandem with gremlin console?

softngineer commented 4 years ago

I just figured it out. Use wss and use the dns name instead of IP.

go run main.go -h "wss://:8182"