public async Task Send(Message message) { try { await _retryPolicy.Retry(() => _topicClient.SendAsync(message)).ConfigureAwait(false); } catch (InvalidOperationException exception) when(exception.Message.Contains("been consumed")) { // this is okay, it means we timed out and upon retry the message was accepted } }
Task IRoutingSlipEventPersister.Persist <T>(Guid trackingNumber, T @event) { FilterDefinition <RoutingSlipDocument> filterDefinition = Builders <RoutingSlipDocument> .Filter.Eq(x => x.TrackingNumber, trackingNumber); UpdateDefinition <RoutingSlipDocument> update = Builders <RoutingSlipDocument> .Update.AddToSet(x => x.Events, @event); return(_retryPolicy.Retry(async() => { var result = await _collection.UpdateOneAsync(filterDefinition, update, new UpdateOptions { IsUpsert = true }).ConfigureAwait(false); if (!result.IsAcknowledged) { throw new SaveEventException(trackingNumber, "Write was not acknowledged"); } if (result.UpsertedId == null) { if (result.IsModifiedCountAvailable && result.ModifiedCount != 1) { throw new SaveEventException(trackingNumber, $"Multiple documents were modified: {result.ModifiedCount}"); } } })); }
async Task <ConnectionContext> CreateConnection(ISupervisor supervisor) { return(await _connectionRetryPolicy.Retry(async() => { if (supervisor.Stopping.IsCancellationRequested) { throw new OperationCanceledException($"The connection is stopping and cannot be used: {_configuration.HostAddress}"); } IConnection connection = null; try { TransportLogMessages.ConnectHost(_configuration.Settings.ToString()); connection = _configuration.Settings.CreateConnection(); return new AmazonSqsConnectionContext(connection, _configuration, _hostTopology, supervisor.Stopped); } catch (OperationCanceledException) { throw; } catch (Exception ex) { throw new AmazonSqsConnectException("Connect failed: " + _configuration.Settings, ex); } }, supervisor.Stopping).ConfigureAwait(false)); }
async Task Run() { while (!IsStopping) { await _retryPolicy.Retry(async() => { try { _supervisor = _supervisorFactory(); await _context.OnTransportStartup(_supervisor, Stopping).ConfigureAwait(false); if (IsStopping) { return; } await _supervisor.Send(_transportPipe, Stopped).ConfigureAwait(false); } catch (ConnectionException exception) { await NotifyFaulted(exception).ConfigureAwait(false); throw; } catch (OperationCanceledException exception) { throw await NotifyFaulted(exception, "ReceiveTransport canceled: ").ConfigureAwait(false); } catch (Exception exception) { throw await NotifyFaulted(exception, "ReceiveTransport faulted: ").ConfigureAwait(false); } }, Stopping).ConfigureAwait(false); } }
private static void AttempRetryOnException(String logPrefix, Request request, VolleyError exception) { IRetryPolicy retryPolicy = request.GetRetryPolicy(); int oldTimeout = request.GetTimeoutMs(); try { retryPolicy.Retry(exception); } catch (VolleyError e) { request.AddMarker(String.Format("{0}-timeout-giveup[timeout={1}]", logPrefix, oldTimeout)); throw e; } request.AddMarker(String.Format("{0}-retry [timeout-{1}]", logPrefix, oldTimeout)); }
async Task <ConnectionContext> CreateConnection(ISupervisor supervisor) { return(await _connectionRetryPolicy.Retry(async() => { if (supervisor.Stopping.IsCancellationRequested) { throw new OperationCanceledException($"The connection is stopping and cannot be used: {_configuration.Description}"); } IConnection connection = null; try { TransportLogMessages.ConnectHost(_configuration.Description); connection = _configuration.Settings.CreateConnection(); connection.Start(); LogContext.Debug?.Log("Connected: {Host} (client-id: {ClientId}, version: {Version})", _configuration.Description, connection.ClientId, connection.MetaData.NMSVersion); return new ActiveMqConnectionContext(connection, _configuration, _hostTopology, supervisor.Stopped); } catch (OperationCanceledException) { connection?.Dispose(); throw; } catch (NMSConnectionException ex) { connection?.Dispose(); throw new ActiveMqConnectException("Connection exception: " + _configuration.Description, ex); } catch (Exception ex) { connection?.Dispose(); throw new ActiveMqConnectException("Create Connection Faulted: " + _configuration.Description, ex); } }, supervisor.Stopping).ConfigureAwait(false)); }
async Task <ConnectionContext> CreateConnection(IAsyncPipeContextAgent <ConnectionContext> asyncContext, IAgent supervisor) { return(await _connectionRetryPolicy.Retry(async() => { if (supervisor.Stopping.IsCancellationRequested) { throw new OperationCanceledException($"The connection is stopping and cannot be used: {_configuration.HostAddress}"); } IConnection connection = null; try { TransportLogMessages.ConnectHost(_configuration.Settings.ToString()); connection = _configuration.Settings.CreateConnection(); var connectionContext = new AmazonSqsConnectionContext(connection, _configuration, _hostTopology, supervisor.Stopped); await asyncContext.Created(connectionContext).ConfigureAwait(false); return connectionContext; } catch (OperationCanceledException) { await asyncContext.CreateCanceled().ConfigureAwait(false); throw; } catch (Exception ex) { LogContext.Error?.Log(ex, "Amazon SQS connection failed"); await asyncContext.CreateFaulted(ex).ConfigureAwait(false); throw new AmazonSqsConnectException("Connect failed: " + _configuration.Settings, ex); } })); }
public Task Send(BrokeredMessage message) { return(_retryPolicy.Retry(() => _queueClient.SendAsync(message))); }
IEnumerator IEnumerable.GetEnumerator() { return(_retryPolicy.Retry(() => _queryable.GetEnumerator())); }
public static void Retry(this IRetryPolicy retryPolicy, Action action) { retryPolicy.Retry <object>(() => { action(); return(null); }); }
public static void SubmitChangesRetry(this DataContext dataContext, ConflictMode failureMode, IRetryPolicy retryPolicy) { retryPolicy.Retry(() => dataContext.SubmitChanges(failureMode)); }
public static void ExecuteCommandRetry(this DataContext dataContext, IRetryPolicy retryPolicy, string command, params object[] parameters) { retryPolicy.Retry(() => dataContext.ExecuteCommand(command, parameters)); }
public static void SubmitChangesRetry(this DataContext dataContext, IRetryPolicy retryPolicy) { retryPolicy.Retry(() => dataContext.SubmitChanges()); }
async Task <ConnectionContext> CreateConnection(ISupervisor supervisor) { return(await _connectionRetryPolicy.Retry(async() => { if (supervisor.Stopping.IsCancellationRequested) { throw new OperationCanceledException($"The connection is stopping and cannot be used: {_description}"); } IConnection connection = null; try { TransportLogMessages.ConnectHost(_description); if (_configuration.Settings.EndpointResolver != null) { connection = _connectionFactory.Value.CreateConnection(_configuration.Settings.EndpointResolver, _configuration.Settings.ClientProvidedName); } else { var hostNames = new List <string>(1) { _configuration.Settings.Host }; connection = _connectionFactory.Value.CreateConnection(hostNames, _configuration.Settings.ClientProvidedName); } LogContext.Debug?.Log("Connected: {Host} (address: {RemoteAddress}, local: {LocalAddress})", _description, connection.Endpoint, connection.LocalPort); var connectionContext = new RabbitMqConnectionContext(connection, _configuration, _hostTopology, _description, supervisor.Stopped); connectionContext.GetOrAddPayload(() => _configuration.Settings); return (ConnectionContext)connectionContext; } catch (ConnectFailureException ex) { connection?.Dispose(); throw new RabbitMqConnectionException("Connect failed: " + _description, ex); } catch (BrokerUnreachableException ex) { connection?.Dispose(); throw new RabbitMqConnectionException("Broker unreachable: " + _description, ex); } catch (OperationInterruptedException ex) { connection?.Dispose(); throw new RabbitMqConnectionException("Operation interrupted: " + _description, ex); } catch (OperationCanceledException) { throw; } catch (Exception ex) { connection?.Dispose(); throw new RabbitMqConnectionException("Create Connection Faulted: " + _description, ex); } }, supervisor.Stopping).ConfigureAwait(false)); }
// The Execute method executes queries that return a single value (instead of an enumerable sequence of values). // Expression trees that represent queries that return enumerable results are executed when their associated IQueryable object is enumerated. // From http://msdn.microsoft.com/en-us/library/bb535032(v=vs.100).aspx public object Execute(Expression expression) { return(_retryPolicy.Retry(() => _queryProvider.Execute(expression))); }