Article DetailsDetailsHelp Details neo4j:// URI routing context in Neo4j 4.x drivers is operationally similar to bolt+routing:// in 3.5. In practice though, if causal cluster instances are behind a load-balancer, accessing with a neo4j:// connection to the loadbalancer would establish the routing context automatically. In such case, the client driver essentially gets assigned a core (with or without a load balancer), grabs the routing table and subsequently, ignores the load balancer. Load balancers or rotating DNS can be used to make an initial connection to a cluster, but after an initial connection, the load balancer is no longer consulted and rather balancing will be taken care of internally, if using the neo4j:// URI context. This article aims to provide an example set of configurations and the corresponding driver URI context for successful client-server reachability. Prerequisites: Assuming we use a load balancer to balance the initial connection and then allowing the driver to route to the members and not using the load-balancer for transaction routing. Explicitly disable encryption at the client/driver to rule out any decryption issues. Set the bolt, http and https advertised addresses to the publically available IP address (or FQDN) of the corresponding host neo4j instance. Ensure that the DNS is correctly resolving the configured A records, perhaps via a forward and reverse nslookup. Get the output of dbms.cluster.routing.getRoutingTable() and dbms.routing.getRoutingTable(). The address shown by the output for each core, should be the value for the dbms.default_advertised_address set in neo4j.conf of respective cluster members. Key considerations: If assigning host names to cores, e.g. clustercore1, clustercore2 and clustercore3, it must be ensured that fully qualified domain names are used, for example clustercore1.mydomain.com. That is because of a difference in our windows and linux environments. On linux we have an internal standard whereby the resolver searches for the hosts in different domains, so just host names would suffice. This is not the case by default in windows and hence fully qualified domain names should be used. Importantly, exposure of the cluster to and from the perspective of the client, with correctly resolvable IPs is mandatory. The client therefore, that can see the load balancer domain name, also has to be able to see the individual addresses exactly as exposed in the routing table. Once the client acquires the routing table it will largely ignore the load balancer. If an error such as “Unable to establish remote connection: Database is unreachable with specified configuration" is reported at the client, it is highly likely that the addresses shown by the cluster overview, were not accessible to the client. It therefore is advisable to not go with a single dns discovery. An example driver connection from an API would look like this: var driver = await GetDriverInstance(AuthTokens.Basic("neo4j", "yourpassword"), "neo4j://clustercore1.mydomain.com”, "neo4j://clustercore2.mydomain.com”, "neo4j://clustercore3.mydomain.com”); or var uris = new List<string>{"neo4j://clustercore1.mydomain.com", "neo4j://clustercore2.mydomain.com", "neo4j://clustercore3.mydomain.com"}; var anotherDriver = await GetDriverInstance(AuthTokens.Basic("neo4j", "yourpassword"), uris.ToArray()); Note further that Cluster discovery is now implemented in Neo4j 4.x via AKKA, instead of Hazelcast, and a few minor changes have been made as part of this transition: The discovery_advertised_address hostname and port must exactly match those configured for the discovery of other members. When discovery_type=LIST is used, this means that it is the list of addresses in initial_discovery_members which must match the respective advertised addresses of each server. When using any other discovery types (DNS, SRV, K8S), then it is the configuration in the external service which must match. Sample Neo4j Configurations: In the example below, we define three DNS names for the public IPs of the cores: Further, the public <→ private IP mapping is done as below: 3.162.95.20 - 172.30.34.210 3.162.95.21 - 172.30.34.211 3.162.95.22 - 172.30.34.212 Initialising the cluster with below configurations, we see the routing table from CALL dbms.routing.getRoutingTable() as: +-------------------------------------------------------------------------------------------------------------+ | ttl | servers | 300 | [{addresses: [“clustercore1.mydomain.com:7687"], role: "WRITE"}, {addresses: ["clustercore2.mydomain.com:7687"", "clustercore3.mydomain.com:7687""], role: "READ"}, {addresses: ["clustercore1.mydomain.com:7687"", "clustercore2.mydomain.com:7687"", "clustercore3.mydomain.com:7687""], role: "ROUTE"}] | +-------------------------------------------------------------------------------------------------------------+ Notice that by the following Neo4j configurations, we advertise the 7687 (bolt) port on the public IPs/DNS names. Clustering is handled on the internal ips. It is optional to define dns names for the internal ips . The below configurations allow access internally on 5000,6000,7000 and from the outside to 7687. The configurations listed below are for Neo4j version 4.0, but the same can be used for 3.x with a couple of configuration name differences, Further note that the default configuration for causal_clustering.discovery_type=LIST is used in our example below. Cluster-Specific configurations in neo4j.conf (only relevant configurations listed): neo4j.conf on clustercore1: dbms.mode=CORE dbms.default_listen_address=0.0.0.0 dbms.default_advertised_address=clustercore1.mydomain.com causal_clustering.initial_discovery_members=172.30.34.210:5000,172.30.34.210:5000,172.30.34.210:5000 causal_clustering.minimum_core_cluster_size_at_formation=3 causal_clustering.minimum_core_cluster_size_at_runtime=3 causal_clustering.discovery_advertised_address=172.30.34.210:5000 causal_clustering.transaction_advertised_address=172.30.34.210:6000 causal_clustering.raft_advertised_address=172.30.34.210:7000 neo4j.conf on clustercore2: dbms.mode=CORE dbms.default_listen_address=0.0.0.0 dbms.default_advertised_address=clustercore2.mydomain.com causal_clustering.minimum_core_cluster_size_at_formation=3 causal_clustering.minimum_core_cluster_size_at_runtime=3 causal_clustering.initial_discovery_members=172.30.34.211:5000,172.30.34.211:5000,172.30.34.211:5000 causal_clustering.discovery_advertised_address=172.30.34.211:5000 causal_clustering.transaction_advertised_address=172.30.34.211:6000 causal_clustering.raft_advertised_address=172.30.34.211:7000 neo4j.conf on clustercore3: dbms.mode=CORE dbms.default_listen_address=0.0.0.0 dbms.default_advertised_address=clustercore1.mydomain.com causal_clustering.minimum_core_cluster_size_at_formation=3 causal_clustering.minimum_core_cluster_size_at_runtime=3 causal_clustering.initial_discovery_members=172.30.34.212:5000,172.30.34.212:5000,172.30.34.212:5000 causal_clustering.discovery_advertised_address=172.30.34.212:5000 causal_clustering.transaction_advertised_address=172.30.34.212:6000 causal_clustering.raft_advertised_address=172.30.34.212:7000 References: https://neo4j.com/docs/migration-guide/4.0/surface-changes/#surface-changes-cluster-discovery https://neo4j.com/docs/driver-manual/4.0/client-applications/#initial-address-resolution Last Modified: 2020-08-20 12:54:46 UTC by Umar Muzammil. Relevant for Neo4j Versions: 3.3, 3.4, 3.5, 4.0, 4.1. Relevant keywords routing, causal, cluster, uri. InformationTitleRouting context URIs and externally Load Balancing a Causal ClusterArticle Created Date3/15/2024, 10:56 PMURL Name360051190733-Routing-context-URIs-and-externally-Load-Balancing-a-Causal-ClusterLast Modified Date5/9/2024, 4:15 AM