The first lesson is to create a project in IDEA, with some twists and turns. Here is a Demo that reads the “Graph of the Gods” data from the JanusGraph example and prints it, using Hbase+ES. Janusgraph is 0.4.0
Official Java dependency
<dependency>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph-core</artifactId>
<version>0.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.tinkerpop</groupId>
<artifactId>gremlin-driver</artifactId>
<version>3.4.1 track</version>
</dependency>
Copy the code
The Demo code
Note: Use JanusGraph Embedded access, also known as Embedded
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.janusgraph.core.JanusGraph;
import org.janusgraph.core.JanusGraphFactory;
import java.util.List;
public class JanusConnect {
public static void main(String[] args) throws Exception {
// Graph is similar to Spark's SparkSession object, a unified access point
JanusGraph graph = JanusGraphFactory.build()
.set("storage.backend"."hbase")
.set("storage.hostname"."10.110.120.3 10.110.120.1, 10.110.120.2,")
.set("index.search.backend"."elasticsearch")
.set("storage.hbase.table"."testgraph") // There is already data in the table
.set("index.search.hostname"."10.110.120.3 10.110.120.1, 10.110.120.2,")
.open();
GraphTraversalSource g = graph.traversal();
// Next () retrieves the vertex, the first action starts the transaction automatically, similar to Spark's action operator
// g.addV("person").property("name", "John").next();
// g.addV("person").property("name", "Snow").next();
// g.addV("person").property("name", "Erya").next();
// g.tx().commit();
System.out.println("Vertex count = " + g.V().count().next());
System.out.println("Edges count = " + g.E().count().next());
System.out.println("++++++++ chart structure +++++++++" + graph.openManagement().printSchema());
List<Vertex> ls = g.V().has("name").toList();
for (Vertex v : ls) {
System.out.println("The tag is ======" + v.label() + "====== name is:" + v.value("name")); } g.close(); graph.close(); }}Copy the code
An error occurs during Demo execution. Procedure
Exception in thread "main" java.lang.IllegalArgumentException: Could not find implementation class: org.janusgraph.diskstorage.hbase.HBaseStoreManager
Caused by: java.lang.ClassNotFoundException: org.janusgraph.diskstorage.hbase.HBaseStoreManager
Copy the code
The reason:
The storage backend of my demo is HBase, because Janusgraph-core lacks the corresponding class package.
Solutions:
Pom. XML is added:
<dependency>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph-all</artifactId>
<version>0.4.0</version>
</dependency>
Copy the code
If an error is reported after a while
Exception in thread "main" java.lang.IllegalArgumentException: Could not instantiate implementation: org.janusgraph.diskstorage.es.ElasticSearchIndex
Caused by: java.lang.ClassNotFoundException: org.apache.http.concurrent.FutureCallback
Copy the code
Reasons and solutions
Index back end is ES, missing HTTP related classes, continue to add to the pom.xml file:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5</version>
</dependency>
Copy the code
Continue to execute demo. It is running successfully.
Partial query output:
The tag is ============ Monster ======== and the name is: Hydra 10:45:51. 997. [the main] the DEBUG O.J.D.H base. HBaseKeyColumnValueStore - Generated HBase Filter ColumnRangeFilter [$, %) tag is ============ God ======== name is: Jupiter 10:45:52. 001. [the main] the DEBUG O.J.D.H base. HBaseKeyColumnValueStore - Generated HBase Filter ColumnRangeFilter [$, %) tag is ============demigod======== name is: Hercules 10:45:52. 005. [the main] the DEBUG O.J.D.H base. HBaseKeyColumnValueStore - Generated HBase Filter ColumnRangeFilter [$, %) tag is ============ God ======== name is: Pluto 10:45:52. 011. [the main] the DEBUG O.J.D.H base. HBaseKeyColumnValueStore - Generated HBase Filter ColumnRangeFilter [$, %) tag is ============ Monster ======== name is: CerberusCopy the code
Archived: [JanusGraph Study Notes]
The problem of notes
JanusGraph Learning Notes – Problems and Solutions (Total)