Search code examples
c#.net-coreneo4jneo4jclient

Connect to Neo4j Causal Cluster using neo4jclient


I am using neo4jClient with a causal cluster hosted on aws via the AMI.

I just recently moved across to this setup before i was using a single server now its multiple (3 in my case).

How do i correctly configure the connection string to connect to a cluster so that the neo4j client is aware of the whole cluster and can distribute reads writes etc correctly?

Running this command gives me all the servers in my cluster.

CALL dbms.cluster.routing.getServers()

[
    {
        "addresses": [
            "100.100.100.1:7687"
        ],
        "role": "WRITE"
    },
    {
        "addresses": [
            "100.100.100.2:7687",
            "100.100.100.3:7687"
        ],
        "role": "READ"
    },
    {
        "addresses": [
            "100.100.100.1:7687",
            "100.100.100.2:7687",
            "100.100.100.3:7687"
        ],
        "role": "ROUTE"
    }
]

Currently i have my neo4jclient setup connecting to the instance labeled 'Write', will it automatically discover the other servers?

services.AddSingleton(s => NeoServerConfiguration.GetConfiguration(new Uri(Configuration.GetConnectionString("Neo4jConnection")), appSettings.Neo4jUser, appSettings.Neo4jPassword));

The NeoServerConfiguration only seems to allow you to connect to a single instance not specify multiple.


Solution

  • For Neo4jClient - you need to be using the BoltGraphClient and then the URI you connect to is:

    bolt+routing://100.100.100.1:7687

    Though it could be any of your IPs.

    It won't work with the standard http endpoint - so you need to use bolt.

    If you're using the Neo4j-Driver and you're trying version 4.x - then instead of bolt+routing you would use neo4j (i.e. neo4j://ip)