我已经在我的应用程序中初始化了janus graph实例。我使用FERMA OGM与之交互。我还想提供对它的网络访问,所以我考虑在嵌入式模式下使用gremlin服务器。
我是这样做的:
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("gremlin-server-simple.yaml");
Settings settings = Settings.read(inputStream);
settings.graphs.clear();
GremlinServer gremlinServer = new GremlinServer(settings);
GraphManager graphManager = gremlinServer.getServerGremlinExecutor().getGraphManager();
graphManager.putGraph("graph", jg);
// jg - graph instance
...
gremlinServer.start();
gremlin服务器简单。yaml:
host: localhost
port: 8182
scriptEvaluationTimeout: 30000
channelizer: org.apache.tinkerpop.gremlin.server.channel.WebSocketChannelizer
graphManager: org.janusgraph.graphdb.management.JanusGraphManager
graphs: {}
scriptEngines: {
gremlin-groovy: {
plugins: { com.mallcloud.shortesttrack.metadata.commons.gremlin.ModJanusGraphJsrGremlinPlugin: {},
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#*]}
},
imports: [java.lang.Math],
staticImports: [java.lang.Math.PI],
scripts: []}}
serializers:
- { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, 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.GraphSONMessageSerializerGremlinV1d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
- { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
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
resultIterationBatchSize: 64
writeBufferLowWaterMark: 32768
writeBufferHighWaterMark: 65536
但我不能为我的graph实例定义绑定(g,graph)-
jg
。
关于这个
programmatically-add-global-variables-to-gremlin-server
主题有一个答案,它需要使用BindingsGremlinPlugin来添加绑定。
但我不知道怎么做——我应该在我的gremlin conf中添加带有插件类和绑定的字符串,还是必须从代码中添加绑定(以某种方式)?
更新-根据答案,我通过修改
Settings
实例:
InputStream inputStream = getClass().getClassLoader().getResourceAsStream(gremlinConfigFile);
Settings settings = Settings.read(inputStream);
// Create arg - bindingsMap
Map<String, Object> arg = new HashMap<>();
arg.put("graph", jg);
arg.put("g", jg.traversal());
// Create method2argMap
Map<String, Object> method2arg = new HashMap<>();
method2arg.put("bindings", arg);
// Add method2argMap to BindingsGremlinPlugin string
settings.scriptEngines.get("gremlin-groovy").plugins.put("org.apache.tinkerpop.gremlin.jsr223.BindingsGremlinPlugin", method2arg);