...
Please note - there is no built-in retry or error handling policy - it is up to you to implement retry logic and error handling. Here is an example showing a retry policy:
Code Block | ||
---|---|---|
| ||
public async Task ProcessMessagesAsync(IMessageBatchContext batchContext, CancellationToken cancellationToken) { var retry = 0; while (!cancellationToken.IsCancellationRequested) { try { await Task.Delay(1000, cancellationToken); // sample async call - send your batch of messages here } catch (OperationCanceledException) { throw; } catch (Exception ex) { // if this is a non-retryable error, then you should rethrow. retry++; var sleepTimeInSeconds = retry > 5 ? 60 : 10; var errorMessage = $"{ex.Message}\n(failed {retry} time(s), next retry in {sleepTimeInSeconds}s)"; Logger.Write(EventSeverity.Error, errorMessage); RealtimeDeviceDisplayStatus.SetSummaryText(errorMessage, Colors.Orange); await Task.Delay(TimeSpan.FromSeconds(sleepTimeInSeconds), cancellationToken); } } } |