gpt4 book ai didi

gremlin - 更改 gremlin 服务器中的默认序列化以使用 GraphS ON V1

转载 作者:行者123 更新时间:2023-12-05 02:56:50 26 4
gpt4 key购买 nike

我正在尝试将 Gremlin http 服务器的输出格式更改为如下所示的非类型化 JSON 对象。

{
"requestId": "320599c8-7d49-4cc6-87a6-42115009f90c",
"status": {
"message": "",
"code": 200,
"attributes": {}
},
"result": {
"data": [
{
"info": [
{
"total_seen": [
2845
],
"first_seen": [
1501568446000
],
"last_seen": [
1580157081000
],
"value": [
"http://test.com"
]
}
]
}
],
"meta": {}
}
}

但是我从服务器得到的响应是打字的

{
"requestId": "e8621470-7ee7-4f6b-a8ea-1d49c85093c8",
"status": {
"message": "",
"code": 200,
"attributes": {
"@type": "g:Map",
"@value": []
}
},
"result": {
"data": {
"@type": "g:List",
"@value": [
{
"@type": "g:Map",
"@value": [
"info",
{
"@type": "g:List",
"@value": [
{
"@type": "g:Map",
"@value": [
"total_seen",
{
"@type": "g:List",
"@value": [
{
"@type": "g:Int32",
"@value": 2797
}
]
},
"first_seen",
{
"@type": "g:List",
"@value": [
{
"@type": "g:Int64",
"@value": 1501568446000
}
]
},
"last_seen",
{
"@type": "g:List",
"@value": [
{
"@type": "g:Int64",
"@value": 1578774368000
}
]
},
"vertex_type",
{
"@type": "g:List",
"@value": [
"url"
]
},
"url_value",
{
"@type": "g:List",
"@value": [
"http://test.com"
]
}
]
}
]
}
]
}
]
},
"meta": {
"@type": "g:Map",
"@value": []
}
}
}

我尝试通过评论 GraphSON V2 和 V3 来更改 gremlin-server.yaml 中的设置

# Copyright 2019 JanusGraph Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

host: 127.0.0.1
port: 8182
scriptEvaluationTimeout: 30000
channelizer: org.apache.tinkerpop.gremlin.server.channel.WebSocketChannelizer
graphs: {
graph: conf/gremlin-server/janusgraph-cassandra-es-server.properties
}
scriptEngines: {
gremlin-groovy: {
plugins: { org.janusgraph.graphdb.tinkerpop.plugin.JanusGraphGremlinPlugin: {},
org.apache.tinkerpop.gremlin.server.jsr223.GremlinServerGremlinPlugin: {},
org.apache.tinkerpop.gremlin.tinkergraph.jsr223.TinkerGraphGremlinPlugin: {},
org.apache.tinkerpop.gremlin.jsr223.ImportGremlinPlugin: {classImports: [java.lang.Math], methodImports: [java.lang.Math#*]},
org.apache.tinkerpop.gremlin.jsr223.ScriptFileGremlinPlugin: {files: [scripts/empty-sample.groovy]}}}}
serializers:
- { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
- { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0, config: { serializeResultToString: true }}
# - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
# Older serialization versions for backwards compatibility:
- { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
- { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, config: {ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
- { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }}
# - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
- { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistryV1d0] }}
- { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistryV1d0] }}
processors:
- { className: org.apache.tinkerpop.gremlin.server.op.session.SessionOpProcessor, config: { sessionTimeout: 28800000 }}
- { className: org.apache.tinkerpop.gremlin.server.op.traversal.TraversalOpProcessor, config: { cacheExpirationTime: 600000, cacheMaxSize: 1000 }}
metrics: {
consoleReporter: {enabled: true, interval: 180000},
csvReporter: {enabled: true, interval: 180000, fileName: /tmp/gremlin-server-metrics.csv},
jmxReporter: {enabled: true},
slf4jReporter: {enabled: true, interval: 180000},
gangliaReporter: {enabled: false, interval: 180000, addressingMode: MULTICAST},
graphiteReporter: {enabled: false, interval: 180000}}
maxInitialLineLength: 4096
maxHeaderSize: 8192
maxChunkSize: 8192
maxContentLength: 65536
maxAccumulationBufferComponents: 1024

如果有人能告诉我我在这里做错了什么,我会很高兴。谢谢。

最佳答案

服务器日志输出可能会显示指向问题的错误,但我的猜测是您正在尝试连接服务器无法识别的驱动程序序列化器配置,因此它默认为 GraphSON 3.0序列化。这种变化发生在很久以前,回到TINKERPOP-1565。对于 3.3.0 版本。

当我们开始插入 GraphSON 3.0 时,我们希望它成为默认的基于 JSON 的网络序列化格式,因此我们为它提供了“application/json”mime 类型,该类型以前是无类型的 GraphSON 1.0。因此,您需要一些自定义配置来让驱动程序和服务器识别您想要发生的事情:

gremlin> cluster = Cluster.build().serializer(new GraphSONMessageSerializerV1d0()).create()
==>localhost/127.0.0.1:8182
gremlin> client = cluster.connect()
==>org.apache.tinkerpop.gremlin.driver.Client$ClusteredClient@277b8fa4
gremlin> x = client.submit("[1,2,3]").all().get()
==>result{object=1 class=java.lang.Integer}
==>result{object=2 class=java.lang.Integer}
==>result{object=3 class=java.lang.Integer}

您可以看到您必须显式构建 GraphSONMessageSerializerV1d0 (在您的情况下,您可能会使用带有 JanusGraphIoRegistry 的构造函数手动将 GraphSONMapper 添加到其中。

总而言之,虽然 GraphSON 1.0 不会有任何进展,但您需要直接使用它,这很好奇。除非你有充分的理由这样做,否则我强烈建议你坚持使用 GraphSON 3.0。它在图形提供者中得到了最广泛的支持,如今对于大多数序列化操作来说,它的速度与 Gryo 一样快。如果您只使用 JVM,我什至建议您尝试使用 GraphBinary 而不是回到 GraphSON 1.0。

关于gremlin - 更改 gremlin 服务器中的默认序列化以使用 GraphS ON V1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60109232/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com