protected virtual void EnableAcknowledgement(IModel channel, CancellationToken token) { _logger.Info("Setting 'Publish Acknowledge' for channel '{channelNumber}'", channel.ChannelNumber); _exclusive.Execute(channel, c => { if (PublishAcknowledgeEnabled(c)) { return; } c.ConfirmSelect(); var dictionary = GetChannelDictionary(c); c.BasicAcks += (sender, args) => { Task.Run(() => { if (args.Multiple) { foreach (var deliveryTag in dictionary.Keys.Where(k => k <= args.DeliveryTag).ToList()) { if (!dictionary.TryRemove(deliveryTag, out var tcs)) { continue; } if (!tcs.TrySetResult(deliveryTag)) { continue; } } } else { _logger.Info("Received ack for {deliveryTag}", args.DeliveryTag); if (!dictionary.TryRemove(args.DeliveryTag, out var tcs)) { _logger.Warn("Unable to find ack tcs for {deliveryTag}", args.DeliveryTag); } tcs?.TrySetResult(args.DeliveryTag); } }, token); };
protected virtual void ExclusiveExecute(IModel channel, Action <IModel> action, CancellationToken token) { Exclusive.Execute(channel, action, token); }