Gremlinq / ExRam.Gremlinq

A .NET object-graph-mapper for Apache TinkerPop™ Gremlin enabled databases.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Running with Cosmos DB emulator

javaadpatel opened this issue · comments

Is there a way to run this using the cosmosdb emulator? Recently the emulator has been updated to support graph. I am getting an error when trying to connect with the below code

            .UseCosmosDb("https://localhost", "test", "testGraph", 
                    "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==", port: 8901);

I don't have any experience with the local emulator. I didn't know it now supports graph, that's awesome. If you are sure it's serving on that particular port (you might wanna verify it with the Tinkerpop Gremlin Console), try omitting "https".

thanks for that hint, I got it connected to the Gremlin console and was able to create a node. This is the microsoft guide to enable graph in the local emulator:
https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator#gremlin-api

I then put this as my config:

 _g = g
                //Since the Vertex and Edge classes contained in this sample implement IVertex resp. IEdge,
                //setting a model is actually not required as long as these classes are discoverable (i.e. they reside
                //in a currently loaded assembly). We explicitly set a model here anyway.
                .UseModel(GraphModel.FromBaseTypes<Vertex, Edge>())

                //Configure Gremlinq to work on a locally running instance of Gremlin server.
                //.UseWebSocket("localhost", GraphsonVersion.V3)

                //For Gremlin Server >= 3.4.0, we need to remove all ReferenceElementStrategies
                //from the traversals, or else we don't get any vertex properties in the returned
                //json-payloads and we end up with NullReferenceExceptions. Uncomment below
                //when running on Gremlin Server >= 3.4.0.
                //.RemoveStrategies("ReferenceElementStrategy")

                //Uncomment below, comment above and enter appropriate data to configure Gremlinq to work on CosmosDB!
                .UseCosmosDb(
                    hostname: "localhost",
                    database: "db1",
                    graphName: "coll1",
                    authKey: "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
                    port: 8901
                );

I get an error saying can't do the SSL handshake,

image

but I don't know where to specify to disable SSL, from the settings I don't think the local emulator supports SSL based on this line in the .yaml file:

connectionPool: {enableSsl: false}

Okay, i changed the config to rather use UseWebSocket like this:


                //Configure Gremlinq to work on a locally running instance of Gremlin server.
                .UseWebSocket(
                    hostname: "localhost",
                    graphsonVersion: GraphsonVersion.V2, 
                    port: 8901,
                    username: "/dbs/db1/colls/coll1",
                    password: "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==");

, it seems the local emulator doesn't support GraphsonVersion.V3 because setting it to V3 gave this error:

image

but after changing to v2, now i get this error:
image

I see from the .yaml file that emulator sets up that it specifies a serializer:

serializer: { 
    className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0,
    config: { 
             serializeResultToString: true  
    }
}

and I see UseWebSocket has a parameter to pass in an additional serializer, not sure if this could be something that I need to set.

Alright, so the local emulator apparently doesn't use SSL. What's the package version of ExRam.Gremlinq you're using?

I am using one of the awesome samples you have provided, the version in your sample project is v7.0.0-preview-0126

Have a look at the UseCosmosDB extension method here. Copy the whole file into your project, set useSSL to false. If it works, and you don't mind, you could maybe provide a PR for a potential "UseCosmosDBEmulator" extension...

amazing! it is working :)

I would be happy to make a PR, I can either add a UseCosmosDBEmulator or just open up the setting ssl like this :

public static IConfigurableGremlinQuerySource UseCosmosDb(this IConfigurableGremlinQuerySource source, string hostname, string database, string graphName, string authKey, bool enableSSL = false, int port = 443)

on UseCosmosDb which would you prefer? And if you don't mind I can make an update to the readme to say how to setup the emulator?

UseCosmosDBEmulator would be just fine. An update to the readme (or the samples) would be awesome.

i've made the PR, i've never contributed to someone else's repository before, so I hope that I have done this correctly and you can see it.

Also, I couldn't update the sample project because when I cloned the repo, the samples wouldn't load
image

this is in VS 2019.

When cloned, you need to init your git submodules because the samples are from another repo:

git submodule init
git submodule update

Fixed by #24.