/// <summary> /// Acknowledges single message /// </summary> /// <param name="consumer">The consumer</param> /// <param name="deliveryTag">The delivery tag</param> /// <param name="cancellationToken">The cancellation token</param> public static Task AckAsync <TPullResult>( this IPullingConsumer <TPullResult> consumer, ulong deliveryTag, CancellationToken cancellationToken = default ) where TPullResult : IPullResult { Preconditions.CheckNotNull(consumer, "consumer"); return(consumer.AckAsync(deliveryTag, false, cancellationToken)); }
/// <summary> /// Rejects all messages of the batch /// </summary> /// <param name="consumer">The consumer</param> /// <param name="deliveryTag">The delivery tag of the batch</param> /// <param name="requeue">True if all messages of batch should be returned to the queue</param> /// <param name="cancellationToken">The cancellation token</param> public static Task RejectBatchAsync <TPullResult>( this IPullingConsumer <TPullResult> consumer, ulong deliveryTag, bool requeue = false, CancellationToken cancellationToken = default ) where TPullResult : IPullResult { Preconditions.CheckNotNull(consumer, "consumer"); return(consumer.RejectAsync(deliveryTag, true, requeue, cancellationToken)); }
/// <summary> /// Pulls a batch of messages /// </summary> /// <param name="consumer">The consumer</param> /// <param name="batchSize">The size of batch</param> /// <param name="cancellationToken">The cancellation token</param> /// <returns>Batch of messages</returns> public static async Task <PullBatchResult <TPullResult> > PullBatchAsync <TPullResult>( this IPullingConsumer <TPullResult> consumer, int batchSize, CancellationToken cancellationToken = default ) where TPullResult : IPullResult { Preconditions.CheckNotNull(consumer, "consumer"); var messages = new List <TPullResult>(batchSize); for (var i = 0; i < batchSize; ++i) { var pullResult = await consumer.PullAsync(cancellationToken).ConfigureAwait(false); if (!pullResult.IsAvailable) { break; } messages.Add(pullResult); } return(new PullBatchResult <TPullResult>(messages)); }