Connecting gremlin CLI to a remote tinkerpop gremlin-server
Asked Answered
L

1

7

Using gremlin-javascript, I'm connecting to a remote server using:

const gremlin = require('gremlin')
const Graph = gremlin.structure.Graph
const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection
const graph = new Graph()

const g = graph
  .traversal()
  .withRemote(new DriverRemoteConnection('ws://localhost:8182/gremlin'))

From the gremlin CLI, I can setup a TinkerGraph using

gremlin> graph = TinkerGraph.open()
gremlin> g = graph.traversal()

However, I'd like to connect to my Graph at localhost:8182. This doesnt't quite do the trick:

gremlin> graph = RemoteGraph.open('ws://localhost:8182/gremlin')

And this isn't quite it either:

gremlin> graph = TinkerGraph.open()
gremlin> g = graph.traversal().withRemote(new DriverRemoteConnection('ws://localhost:8182/gremlin'))

How would I connect to this server from the CLI?

Leopoldeen answered 25/10, 2018 at 21:10 Comment(0)
P
13

Gremlin Console has built in support for this and it is described in detail here. The basic connection command is:

gremlin> :remote connect tinkerpop.server conf/remote.yaml
==>Configured localhost/127.0.0.1:8182

at which point you can issue traversals against the remote graph:

gremlin> :> g.V().values('name')
==>marko
==>vadas
==>lop
==>josh
==>ripple
==>peter

If you'd like to drop the :> syntax you can put the REPL in "console" mode and that prefix will no longer be necessary:

gremlin> :remote console
==>All scripts will now be sent to Gremlin Server - [localhost/127.0.0.1:8182]-[5ff68eac-5af9-4140-b3b8-d9311f30c053] - type ':remote console' to return to local mode
Pocahontas answered 25/10, 2018 at 21:22 Comment(1)
Aha, I got as far as the remote connection, but my commands which referenced g were being bounced back. I needed to enter console mode Thanks again!Leopoldeen

© 2022 - 2024 — McMap. All rights reserved.