Closed zhengyingying closed 3 years ago
@zhengyingying HugeGraph has made many changes in the serialization part of Graphson
, which does not guarantee that the tinkerpop-java-client
that can now adapt to Gremlin.
It is currently known that: HugeVertex
and HugeEgde
are not supported by the derivatives of the Gremlin client. (Users should better use our hugegraph-java-client instead, related doc)
So, based in version 0.11.2
, a runnable configuration: (Note: 0.11.2 is a legacy version, watch out the diff in the latest release)
gremlin-server.yaml:
serializers:
- { className: org.apache.tinkerpop.gremlin.driver.ser.GraphBinaryMessageSerializerV1,
config: {
serializeResultToString: false,
ioRegistries: [com.baidu.hugegraph.io.HugeGraphIoRegistry]
}
}
- { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0,
config: {
serializeResultToString: true,
ioRegistries: [com.baidu.hugegraph.io.HugeGraphIoRegistry]
}
}
client driver.yaml:
hosts: [localhost]
port: 8182
serializer: {
className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0,
config: {
serializeResultToString: true
}
}
demo code:
ResultSet results = client.submit("hugegraph.traversal().V()");
results.stream().forEach(result -> {
System.out.println(result.getObject());
// System.out.println(result.getVertex());
});
results = client.submit("hugegraph.traversal().E()");
results.stream().forEach(result -> {
System.out.println(result.getObject());
// System.out.println(result.getEdge());
});
Note: Because deserialization on the gremlin client is not supported, getVertex
and getEdge
methods cannot be used
注意:因为不支持在gremlin客户端的反序列化,所以不能用getVertex和getEdge方法。
@Linary 非常感谢,这个问题已经解决了。
但是通过HugeClient访问远端server,有报错。
还是上述配置,使用下面的代码访问远端的server。
HugeClient hugeClient = new HugeClientBuilder("http://192.168.1.101:8080", "hugegraph").build();
GraphManager graph = hugeClient.graph();
报错如下:
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkNotNull(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;
at com.baidu.hugegraph.util.E.checkNotNull(E.java:31)
at com.baidu.hugegraph.api.API.<init>(API.java:37)
at com.baidu.hugegraph.api.version.VersionAPI.<init>(VersionAPI.java:31)
at com.baidu.hugegraph.driver.VersionManager.<init>(VersionManager.java:31)
at com.baidu.hugegraph.driver.HugeClient.initManagers(HugeClient.java:82)
at com.baidu.hugegraph.driver.HugeClient.<init>(HugeClient.java:63)
at com.baidu.hugegraph.driver.HugeClientBuilder.build(HugeClientBuilder.java:67)
server端可以通过url http://192.168.1.101:8080
访问
Due to the lack of activity, the current issue is marked as stale and will be closed after 20 days, any update will remove the stale label
For the remote server,I have the exactly same problem with you.It's because the guava version is not correctly.
For the remote server,I have the exactly same problem with you.It's because the guava version is not correctly.
@xingtianxia1314 @dosu-bot maybe u could submit a new issue if the context is changed (Or tell us your local environment / server version...etc)
Environment ( 环境信息 - 必填 )
Your Question ( 问题描述 )
希望通过Java代码远程访问Huge Graph Server,但是按照[https://github.com/hugegraph/hugegraph/issues/345]的方法无法实现。
本地hugegraph.yaml文件内容如下:
远程【192.168.1.101】gremlin-server.yaml文件内容如下:
事先在远端【192.168.1.101】HugeGraph数据库中,使用console写入数据: gremlin> hugegraph.traversal().V() ==>[id:1:josh,label:person,type:vertex,properties:[name:josh,age:32,city:Beijing]] ==>[id:2:ripple,label:software,type:vertex,properties:[name:ripple,lang:java,price:199]] ==>[id:1:peter,label:person,type:vertex,properties:[name:peter,age:35,city:Shanghai]] ==>[id:1:vadas,label:person,type:vertex,properties:[name:vadas,age:27,city:Hongkong]] ==>[id:2:lop,label:software,type:vertex,properties:[name:lop,lang:java,price:328]] ==>[id:1:marko,label:person,type:vertex,properties:[name:marko,age:29,city:Beijing]]
本地Java测试代码如下:
报错信息如下: