/// <summary> /// Abandons a message by returning it to the queue. /// </summary> /// <param name="message">The message we want to abandon.</param> /// <returns>Task.</returns> internal async Task Abandon(T message) { if (Messages.TryGetValue(message, out var msg)) { try { Release(message); if (msg.SystemProperties.LockedUntilUtc < DateTime.Now) { Receiver.RenewLockAsync(msg.SystemProperties.LockToken).GetAwaiter().GetResult(); } await Receiver.AbandonAsync(msg.SystemProperties.LockToken).ConfigureAwait(false); } catch (Exception ex) when(ex is MessageLockLostException || ex is MessageNotFoundException) { Logger?.LogWarning(ex, "Error during message Abandon, lock was lost [THIS CAN BE IGNORED - already in use or already processed]"); } catch (Exception e) { Logger?.LogError(e, "Error during message Abandon"); MessageIn?.OnError(e); } } }
public async Task Execute(string id, bool force) { if (string.IsNullOrEmpty(id) && !force) { Console.WriteLine($"No id specified. Use --force if you intend to delete all messages"); } var tokens = await ReceiveMessages(id); var tasks = tokens .Select(t => Receiver.AbandonAsync(t)); await Task.WhenAll(tasks); }
public async Task Execute(string id) { Message message; do { message = await Receiver.ReceiveAsync(TimeSpan.FromSeconds(5)); if (message == null) { Console.WriteLine($"Message with id {id} was not found"); return; } if (message.MessageId == id) { await Receiver.DeadLetterAsync(message.SystemProperties.LockToken); return; } await Receiver.AbandonAsync(message.SystemProperties.LockToken); } while (message != null); }