private void Sending() { try { while (!_publishedMessageQueue.IsCompleted) { if (_publishedMessageQueue.TryTake(out var message, 3000, _cts.Token)) { Task.Run(async() => { try { await _sender.SendAsync(message); } catch (Exception ex) { _logger.LogError(ex, $"An exception occurred when sending a message to the MQ. Topic:{message.Name}, Id:{message.Id}"); } }); } } } catch (OperationCanceledException) { // expected } }
private async Task ProcessPublishedAsync(IStorageConnection connection, ProcessingContext context) { var messages = await GetSafelyAsync(connection.GetPublishedMessagesOfNeedRetry); foreach (var message in messages) { await _publishMessageSender.SendAsync(message); await context.WaitAsync(_delay); } }
private void Sending() { try { while (!_publishedMessageQueue.IsCompleted) { if (_publishedMessageQueue.TryTake(out var message, 100, _cts.Token)) { try { _sender.SendAsync(message); } catch (Exception ex) { _logger.ExceptionOccuredWhileExecuting(message.Name, ex); } } } } catch (OperationCanceledException) { // expected } }