public async Task <IClusterClient> CreateOrleansClient() { if (DeploymentId.IsNullOrWhiteSpace()) { throw new ConfigurationErrorsException($"Cannot connect to Azure silos with null deploymentId."); } if (DataConnectionString.IsNullOrWhiteSpace()) { throw new ConfigurationErrorsException($"Cannot connect to Azure silos with null connectionString."); } Log.Info($"Initializing Orleans Client."); Exception lastException = null; for (var i = 0; i < MaxRetries; i++) { if (i > 0) { // Pause to let Primary silo start up and register await Task.Delay(StartupRetryPause); } try { var client = new ClientBuilder() .UseConfiguration(Configuration) .AddClusterConnectionLostHandler((sender, e) => Log.Info("Orleans cluster connection lost.")) .Build(); // Connect will throw if cannot find Gateways await client.Connect(); return(client); } catch (Exception exc) { lastException = exc; exc.Report("Error initializing Orleans Client. Will retry."); } } if (lastException != null) { throw new OrleansException($"Could not Initialize Client for DeploymentId={DeploymentId}.", lastException); } else { throw new OrleansException($"Could not Initialize Client for DeploymentId={DeploymentId}."); } }