/// <remarks>Throws <see cref="InvalidDiscoveryException"/> if the discovery result is invalid.</remarks> public void Rediscovery() { using (var session = new Session(_conn, _logger)) { var result = session.Run($"CALL {ProcedureName}"); var record = result.Single(); // TODO require an IT to make sure List or IList, Dictionary or IDictionary foreach (var servers in record["servers"].As <List <Dictionary <string, object> > >()) { var addresses = servers["addresses"].As <List <string> >(); var role = servers["role"].As <string>(); switch (role) { case "READ": Readers = addresses.Select(BoltRoutingUri).ToArray(); break; case "WRITE": Writers = addresses.Select(BoltRoutingUri).ToArray(); break; case "ROUTE": Routers = addresses.Select(BoltRoutingUri).ToArray(); break; } } ExpireAfterSeconds = record["ttl"].As <long>(); } if (!Readers.Any() || !Writers.Any() || !Routers.Any()) { throw new InvalidDiscoveryException( $"Invalid discovery result: discovered {Routers.Count()} routers, " + $"{Writers.Count()} writers and {Readers.Count()} readers. A Redisvoery is required."); } }
/// <remarks>Throws <see cref="ProtocolException"/> if the discovery result is invalid.</remarks> /// <remarks>Throws <see cref="ServiceUnavailableException"/> if the no discovery procedure could be found in the server.</remarks> public void Rediscovery() { try { using (var provider = new SingleConnectionBasedConnectionProvider(_conn)) using (var session = new Session(provider, _logger)) { var result = session.Run(DiscoveryProcedure); var record = result.Single(); foreach (var servers in record["servers"].As <List <Dictionary <string, object> > >()) { var addresses = servers["addresses"].As <List <string> >(); var role = servers["role"].As <string>(); switch (role) { case "READ": Readers = addresses.Select(BoltRoutingUri).ToArray(); break; case "WRITE": Writers = addresses.Select(BoltRoutingUri).ToArray(); break; case "ROUTE": Routers = addresses.Select(BoltRoutingUri).ToArray(); break; } } ExpireAfterSeconds = record["ttl"].As <long>(); } } catch (ClientException e) { throw new ServiceUnavailableException( $"Error when calling `getServers` procedure: {e.Message}. " + "Please make sure that there is a Neo4j 3.1+ causal cluster up running.", e); } catch (Exception e) { // for any reason we failed to do a discovery throw new ProtocolException( $"Error when parsing `getServers` result: {e.Message}."); } if (!Readers.Any() || !Routers.Any()) { throw new ProtocolException( $"Invalid discovery result: discovered {Routers.Count()} routers, " + $"{Writers.Count()} writers and {Readers.Count()} readers."); } }
public async Task RediscoveryAsync() { var provider = new SingleConnectionBasedConnectionProvider(_conn); var session = new Session(provider, _logger); try { var result = await session.RunAsync(DiscoveryProcedure).ConfigureAwait(false); var record = await result.SingleAsync().ConfigureAwait(false); ParseDiscoveryResult(record); } catch (Exception e) { HandleDiscoveryException(e); } finally { try { await session.CloseAsync().ConfigureAwait(false); } catch (Exception) { // ignore any exception } await provider.CloseAsync().ConfigureAwait(false); } if (!Readers.Any() || !Routers.Any()) { throw new ProtocolException( $"Invalid discovery result: discovered {Routers.Count()} routers, " + $"{Writers.Count()} writers and {Readers.Count()} readers."); } }
/// <remarks>Throws <see cref="ProtocolException"/> if the discovery result is invalid.</remarks> /// <remarks>Throws <see cref="ServiceUnavailableException"/> if the no discovery procedure could be found in the server.</remarks> public void Rediscovery() { try { using (var provider = new SingleConnectionBasedConnectionProvider(_conn)) using (var session = new Session(provider, _logger)) { var result = session.Run(DiscoveryProcedure); var record = result.Single(); ParseDiscoveryResult(record); } } catch (Exception e) { HandleDiscoveryException(e); } if (!Readers.Any() || !Routers.Any()) { throw new ProtocolException( $"Invalid discovery result: discovered {Routers.Count()} routers, " + $"{Writers.Count()} writers and {Readers.Count()} readers."); } }