/// <summary> /// Sends a single message. /// </summary> /// <param name="message">The message we want to send.</param> internal async Task Send([NotNull] T message) { var qMessage = new Message(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message))) { ContentType = "application/json", Label = message.GetType().GetEntityName() }; await SendPolicy.ExecuteAsync( async() => { try { using (await SenderLock.ReaderLockAsync()) { await Sender.SendAsync(qMessage).ConfigureAwait(false); } } catch { await RebuildSender().ConfigureAwait(false); throw; } }).ConfigureAwait(false); }
/// <summary> /// Sends a single message. /// </summary> /// <param name="message">The message we want to send.</param> internal async Task Send([NotNull] T message) { var qMessage = new Message(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message))) { ContentType = "application/json", Label = message.GetType().GetEntityName() }; await SendPolicy.ExecuteAsync( async() => { try { using (await SenderLock.ReaderLockAsync()) { await Sender.SendAsync(qMessage).ConfigureAwait(false); } } /** * we want to minimize the client rebuild frequency and ideally to reverse the approach * rebuild only when there is valid reason to do so * this list will need to be compiled/maintained */ catch (QuotaExceededException) //let the polly deal with this - retry if allowed { throw; } catch { await RebuildSender().ConfigureAwait(false); throw; } }).ConfigureAwait(false); }