private void OnMessageConfirmation(MessageConfirmationEvent @event) { ConcurrentDictionary <ulong, TaskCompletionSource <object> > requests; if (!unconfirmedChannelRequests.TryGetValue(@event.Channel, out requests)) { return; } var deliveryTag = @event.DeliveryTag; var multiple = @event.Multiple; var isNack = @event.IsNack; if (multiple) { // Fix me: ConcurrentDictionary.Keys acquires all locks, it is very expensive operation and could perform slowly. foreach (var sequenceNumber in requests.Keys.Where(x => x <= deliveryTag)) { TaskCompletionSource <object> confirmation; if (requests.TryGetValue(sequenceNumber, out confirmation)) { Confirm(confirmation, sequenceNumber, isNack); } } } else { TaskCompletionSource <object> confirmation; if (requests.TryGetValue(deliveryTag, out confirmation)) { Confirm(confirmation, deliveryTag, isNack); } } }
private void OnNack(object sender, BasicNackEventArgs args) { EventBus.Publish(MessageConfirmationEvent.Nack((IModel)sender, args.DeliveryTag, args.Multiple)); }