Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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
languagec#
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);
}
}
}