public static Message Last(this IMessageBatch batch)
 {
     if (batch.Messages.Count == 0)
     {
         return(null);
     }
     return(batch.Messages[batch.Messages.Count - 1]);
 }
 public static async Task <long> CommitMarkedIgnoringDisposedAsync(this IMessageBatch batch, CancellationToken cancellationToken)
 {
     try {
         return(await batch.CommitMarkedAsync(cancellationToken));
     } catch (ObjectDisposedException) {
         // ignore
         return(0);
     }
 }
Beispiel #3
0
            public static async Task Do([QueueBatchTrigger(InputQueue, ParallelGets = 2, MaxBackOffInSeconds = 30)] IMessageBatch batch, [Queue(OutputQueue)] CloudQueue output)
            {
                foreach (var message in batch.Messages)
                {
                    await output.AddMessageAsync(new CloudQueueMessage(message.Id));

                    batch.MarkAsProcessed(message);
                }
            }
        private void CheckMessages(List <Message> expected, IMessageBatch actual)
        {
            Assert.AreEqual(expected.Count(), actual.Messages.Count(), "Didn't get all messages");

            foreach (var message in expected)
            {
                Assert.IsTrue(actual.Messages.Any(m => m.Value.SequenceEqual(message.Value)), "Didn't get the same messages");
            }
        }
        public static Task CommitAsync(this IMessageBatch batch, Message message, CancellationToken cancellationToken)
        {
            if (message == null)
            {
                return(Task.FromResult(0));
            }

            batch.MarkSuccessful(message);
            return(batch.CommitMarkedAsync(cancellationToken));
        }
 internal static Task FetchNextAsync(this IMessageBatch batch, Func <IMessageBatch, CancellationToken, Task> onMessagesAsync, ILog log, CancellationToken cancellationToken)
 {
     return(SafeAsync(
                async() => {
         do
         {
             using (var source = new CancellationTokenSource()) {
                 batch.OnDisposed = source.Cancel;
                 using (cancellationToken.Register(source.Cancel)) {
                     await onMessagesAsync(batch, source.Token).ConfigureAwait(false);
                 }
                 batch.OnDisposed = null;
             }
             batch = await batch.FetchNextAsync(cancellationToken).ConfigureAwait(false);
         } while (!batch.IsEmpty() && !cancellationToken.IsCancellationRequested);
         return batch;
     }, log));
 }
 public static bool IsEmpty(this IMessageBatch batch)
 {
     return(ReferenceEquals(batch, MessageBatch.Empty) || batch?.Messages?.Count == 0);
 }
 public static Task CommitAsync(this IMessageBatch batch, CancellationToken cancellationToken)
 {
     return(batch.CommitAsync(batch.Last(), cancellationToken));
 }
 public static void MarkSuccessful(this IMessageBatch batch)
 {
     batch.MarkSuccessful(batch.Last());
 }
Beispiel #10
0
 public static Task Do([QueueBatchTrigger(InputQueue, UseFasterQueues = false)] IMessageBatch batch)
 {
     CountDown.Release(batch.Messages.Count());
     batch.MarkAllAsProcessed();
     return(Task.CompletedTask);
 }
Beispiel #11
0
 public static Task Do([QueueBatchTrigger(InputQueue, ParallelGets = 2, MaxBackOffInSeconds = 1)] IMessageBatch batch)
 {
     // do nothing, do not ack any messages in batch
     return(Task.CompletedTask);
 }
        public override Task OnActivateAsync()
        {
            _messageBatchGrain = GrainFactory.GetGrain <IMessageBatch>(Guid.Empty);

            return(base.OnActivateAsync());
        }