我想监听远程 JanusGraph 上的突变,但我无法找出使其工作的正确设置。
JanusGraph 堆栈:
JanusGraph docker 镜像 **0.5.2(使用 Apache TinkerPop Gremlin 3.4.6)和 cql-es 配置
Cassandra docker 镜像 3.11.6
ElasticSearch docker 镜像 7.3.1
gremlin-server-cql-es.yaml
的序列化器部分已更新为以下行:
- { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry, org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV3d0] }}
- { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0, config: { serializeResultToString: true }}
Java 客户端堆栈:
基于pluradj/janusgraph-java-example
Java8
janusgraph-core 0.5.2
gremlin-driver 3.4.6
remote-objects.yaml
如下所示:
hosts: [127.0.0.1]
port: 8182
serializer: {
className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0,
config: {
ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry, org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV3d0]
}
}
完整代码(没有ConsoleMutationListener
)如下所示:
public static void main(String[] args) {
MutationListener mutationListener = new ConsoleMutationListener("Test");
EventStrategy eventStrategy = EventStrategy.build().addListener(mutationListener).create();
try (GraphTraversalSource g = AnonymousTraversalSource.traversal()
.withRemote("conf/remote-graph.properties")
.withStrategies(eventStrategy)) {
g.addV("person").property("name", "Test").next();
} catch (Exception e) {
e.printStackTrace();
}
}
ConsoleMutationListener
是 TinkerPop 示例 ConsoleMutationListener 的副本使用修改后的构造函数来接受图形名称而不是完整图形,因为 toString()
是唯一使用的方法。
堆栈跟踪:
io.netty.handler.codec.EncoderException: org.apache.tinkerpop.gremlin.driver.exception.ResponseException: An error occurred during serialization of this request [RequestMessage{, requestId=9436b08c-7e31-4fc0-b480-40904055f491, op='bytecode', processor='traversal', args={gremlin=[[withStrategies(EventStrategy)], [addV(person), property(name, Test)]], aliases={g=g}}}] - it could not be sent to the server - Reason: org.apache.tinkerpop.gremlin.driver.ser.SerializationException: java.lang.IllegalArgumentException: Class is not registered: org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy
Note: To register this class use: kryo.register(org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy.class);
at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:107)
at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:716)
at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:708)
at io.netty.channel.AbstractChannelHandlerContext.access$1700(AbstractChannelHandlerContext.java:56)
at io.netty.channel.AbstractChannelHandlerContext$AbstractWriteTask.write(AbstractChannelHandlerContext.java:1102)
at io.netty.channel.AbstractChannelHandlerContext$WriteAndFlushTask.write(AbstractChannelHandlerContext.java:1149)
at io.netty.channel.AbstractChannelHandlerContext$AbstractWriteTask.run(AbstractChannelHandlerContext.java:1073)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:510)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:518)
at io.netty.util.concurrent.SingleThreadEventExecutor$6.run(SingleThreadEventExecutor.java:1044)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.tinkerpop.gremlin.driver.exception.ResponseException: An error occurred during serialization of this request [RequestMessage{, requestId=9436b08c-7e31-4fc0-b480-40904055f491, op='bytecode', processor='traversal', args={gremlin=[[withStrategies(EventStrategy)], [addV(person), property(name, Test)]], aliases={g=g}}}] - it could not be sent to the server - Reason: org.apache.tinkerpop.gremlin.driver.ser.SerializationException: java.lang.IllegalArgumentException: Class is not registered: org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy
Note: To register this class use: kryo.register(org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy.class);
at org.apache.tinkerpop.gremlin.driver.handler.WebSocketGremlinRequestEncoder.encode(WebSocketGremlinRequestEncoder.java:60)
at org.apache.tinkerpop.gremlin.driver.handler.WebSocketGremlinRequestEncoder.encode(WebSocketGremlinRequestEncoder.java:38)
at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:89)
... 12 more
如果我删除 withStrategies(eventStrategy)
,顶点将添加到图表中,并且我也可以正常查询图表。但是,我无法使用 EventStrategy
配置 GraphTraversalSource
。
Q1:我的想法是,具有已定义事件策略的消息无法使用 GryoMessageSerializerV3d0
进行序列化,或者应该以某种方式在服务器端注册突变监听器/事件策略,但我找不到任何关于如何做到这一点的引用。有此类配置的示例吗?
问题2:我做错了什么?是否可以将 TinkerPop 的 EventStrategy 与 JanusGraph 结合使用?
Q3:是否有其他方法来监听远程 JanusGraph 突变?
将序列化器更改为 GraphSONMessageSerializerV3d0
给出:
java.util.concurrent.CompletionException: org.apache.tinkerpop.gremlin.driver.exception.ResponseException: EventStrategy does can only be constructed with instance() or create(Configuration)
at java.util.concurrent.CompletableFuture.reportJoin(CompletableFuture.java:375)
at java.util.concurrent.CompletableFuture.join(CompletableFuture.java:1947)
...
Caused by: org.apache.tinkerpop.gremlin.driver.exception.ResponseException: EventStrategy does can only be constructed with instance() or create(Configuration)
将序列化器更改为 GraphBinaryMessageSerializerV1 会给出:
java.util.concurrent.CompletionException: io.netty.handler.codec.DecoderException: org.apache.tinkerpop.gremlin.driver.ser.SerializationException: The most significant bit should be set according to the format
at java.util.concurrent.CompletableFuture.reportJoin(CompletableFuture.java:375)
at java.util.concurrent.CompletableFuture.join(CompletableFuture.java:1947)
...
Caused by: io.netty.handler.codec.DecoderException: org.apache.tinkerpop.gremlin.driver.ser.SerializationException: The most significant bit should be set according to the format
最佳答案
Q1: What I'm thinking is that message with defined Event Strategy cannot be serialized with GryoMessageSerializerV3d0 or Mutation Listener/Event Strategy should somehow be registered on the server side, but I can't find any references on how to do that.
这是正确的。 EventStrategy
无法跨远程连接工作。
Q2: What am I doing wrong? Is it even possible to use TinkerPop's EventStrategy with JanusGraph?
可以将其与 JanusGraph 一起使用,但只能在嵌入模式下使用,因为 MutationListener
实现不知道如何将事件发送回客户端。驱动程序可能需要一些重大更改来引入支持机制,因此这是一个不小的更改。如果解决了这一点,那么仍然存在序列化问题需要为提供自定义 MutationListeners
的用户解决(尽管也许这只是不允许的)。
Q3: Is there any other approach to listen to remote JanusGraph mutations?
这里的关键词是“远程”,我认为目前不存在任何允许这样做的东西。您需要构建自己的某种类型。一种方法可能是在服务器上使用 EventStrategy
配置“g”,然后添加一个 MutationListener
,将这些事件发送到您可以远程使用的单独队列。您也可以考虑查看JanusGraph Bus并设计一个类似的方案。
关于gremlin - 具有远程 JanusGraph 的突变监听器事件策略抛出序列化异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63134773/