将gremlin服务器中的默认系列化更改为使用GraphSON V1

将gremlin服务器中的默认系列化更改为使用GraphSON V1,gremlin,tinkerpop,janusgraph,gremlin-server,Gremlin,Tinkerpop,Janusgraph,Gremlin Server,我正在尝试将GremlinHTTP服务器的输出格式更改为非类型JSON对象,如下所示 { "requestId": "320599c8-7d49-4cc6-87a6-42115009f90c", "status": { "message": "", "code": 200, "attributes": {} }, "result": { "data": [ { "info": [ {

我正在尝试将GremlinHTTP服务器的输出格式更改为非类型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": []
    }
  }
}
我试图通过评论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序列化。这一变化发生在很久以前,早在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
(在您的情况下,您可能会使用采用
GraphSONMapper
的构造函数手动将
JanusGraphiOreRegistry添加到该函数中)


综上所述,尽管GraphSON 1.0没有走向任何地方,但奇怪的是,您需要直接使用它。除非您有很好的理由这样做,否则我强烈建议您坚持使用GraphSON 3.0。它在图形提供商中拥有最广泛的支持,对于大多数序列化操作,它的速度与Gryo差不多。如果您不使用在JVM上,我甚至建议尝试GraphBinary,而不是回到GraphSON 1.0。

谢谢@stephen的回答。即使我们使用GraphSON 3.0,我如何在Gremlin http服务器中获得“非类型化”的JOSN respone。我只是好奇Gremlin-server.yaml文件中是否有任何设置。GraphSON 3.0已键入,并且没有选项可供选择我们通常不希望用户直接使用GraphSON结果,而是希望他们使用自己选择的编程语言处理序列化对象。序列化机制应该是透明的。我想如果您需要原始JSON,您可以执行以下操作之一(1)发送一个脚本并以您选择的形式将您的数据输出为JSON字符串,尽管我们不希望您如此频繁地使用脚本-更喜欢字节码请求或(2)编写您自己的
MessageSerializer
实现,对您的结果进行特殊处理,并将其配置到您的Gremlin服务器中。关于(1)Gremlin字节码请求可能很快就能实现这一功能,非常感谢。最后,我们决定继续使用GraphSON 3.0,并计划编写一个解析器来解析我们需要的内容。