Gremlin.NET 是否支持提交异步字节码?

Arm*_*ade 3 .net c# gremlin .net-core amazon-neptune

有扩展功能异步提交查询在Gremlin.Net,有些人会string建议不要和其他人使用RequestMessage这是不一样可读性使用GraphTraversal功能。

有没有办法异步提交像下面这样的查询,而不提交字符串或RequestMessage

var res = _graphTraversalSource.V().Has("name", "Armin").Out().Values<string>("name").ToList();
Run Code Online (Sandbox Code Playgroud)

多一点上下文

我正在编写一个查询 AWS Neptune 的 API。以下是我得到GraphTraversalSource的单服务的构造函数(不知道我是否应该做RemoteConnection一个单身,并生成一个GraphTraversalSource为每个查询或这是正确的做法):

private readonly GraphTraversalSource _graphTraversalSource;

public NeptuneHandler(string endpoint, int port)
{
    var gremlinClient = new GremlinClient(new GremlinServer(endpoint, port));
    var remoteConnection = new DriverRemoteConnection(gremlinClient);
    _graphTraversalSource = AnonymousTraversalSource.Traversal().WithRemote(remoteConnection);
}
Run Code Online (Sandbox Code Playgroud)

Flo*_*ann 5

您可以使用Promise()终止器步骤异步执行遍历

var names = await g.V().Has("name", "Armin").Out().Values<string>("name").Promise(t => t.ToList());
Run Code Online (Sandbox Code Playgroud)

Promise() takes a callback as its argument that calls the usual terminator step you want to be executed for your traversal which is ToList in your case. If you however only want to get a single result back, then you can just replace ToList() with Next().

Note that I renamed the variable for the graph traversal source to g as that is the usual naming convention for Gremlin.

As I already mentioned in my comment, it is recommended to reuse this graph traversal source g across your application as it can contain configuration that applies to all traversals you want to execute. It also contains the DriverRemoteConnection which uses a connection pool for the communication with the server. By reusing g, you also use the same connection pool for all traversals in your application.