How to connect to TitanDB using Gremlin API

We will be looking into How to connect to TitanDB using Gremlin API in this tutorial. Interacting with TitanDB is bit different than other databases, since you can only use a WebSocket or HTTP Connection. First we will discuss on the challenges and explore a future proof way of interacting with TitanDB from Spark using Scala using Gremlin API. Then we will see how to Configure TitanDB and then use Play framework to connect to TitanDB over HTTP ( RESTful way ). We also may need to submit multiple queries together. we will learn how to combine queries in different ways.

Challanges :

TitanDB supports two types of connections:

WebScoket

HTTP Connection

Most of the projects uses the HTTP Connection option, since it would be easy at times just to get the data using a REST call from the Browser itself. However Scala or Java does not have an API yet to use the JSON Object. You have Python library for the HTTP Connection and Java/Scala Library for the WebSocket. Using the RESTful option from scala is difficult however you would need good Scala REST Client which is future proof and supports SSL as well.

Approach:

After brief research, trail and error; I found that The WS API available as part of the Play framewrk is not only robust but it comes with a wide variaty of support. You can also use the Play REST WS API in a standalone mode without starting the entire play framework.

How to setup Titan DB:

Setting up TitanDB is very straight forward. Just follow the instructions. Once the installation has been completed, open ...installed_dir/conf/gremlin-server/gremlin-server.yaml, then replace the channelizer with org.apache.tinkerpop.gremlin.server.channel.HttpChannelizer.