Exemplo n.º 1
0
        /// <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);
                }
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }