Reputation: 522
I am using JanusGraph. How do I create a connection pool while connecting to JanusGraph remotely and then using the pool to borrow the connection?
right now I am doing something like
private static void init() {
String uri = "localhost";
int poolSize = 5;
graph = JanusGraphFactory.open("inmemory");
cluster = Cluster.build()
.addContactPoint(uri)
.port(8182)
.serializer(new GryoMessageSerializerV1d0(GryoMapper.build().addRegistry(JanusGraphIoRegistry.getInstance())))
.maxConnectionPoolSize(poolSize)
.minConnectionPoolSize(poolSize)
.create();
gts = graph
.traversal()
.withRemote(DriverRemoteConnection.using(cluster));
}
this init method is initialized once. and then anyone who requires connection simple calls the below method
public GraphTraversalSource getConnection() {
return gts.clone();
}
Please note that withRemote() method is being deprecated now. I am not sure am I doing it correctly?
Upvotes: 1
Views: 1948
Reputation: 46226
I think you're confusing some concepts. You only need to use the TinkerPop driver (i.e. Cluster
) if you are connecting to a Graph
instance remotely. In your case you're creating your JanusGraph instance locally, so you can simply do graph.traversal()
and start writing Gremlin. If you hosted your JanusGraph instance in Gremlin Server on the other hand, then you would need to use the withRemote()
option. As you mention withRemote()
in the fashion you are calling it is deprecated, but the javadoc mentions the new method which can also be found in the documentation:
import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;
GraphTraversalSource g = traversal().withRemote(DriverRemoteConnection.using(cluster));
To understand all the different options for connecting to a Graph
instance I'd suggest reading this section of TinkerPop's Reference Documentation.
Upvotes: 2