示例#1
0
        public async Task AQ_Standalone_2()
        {
            queueName = "Test-2-".ToLower() + Guid.NewGuid();
            AzureQueueDataManager manager = await GetTableManager(queueName);

            IEnumerable <CloudQueueMessage> msgs = await manager.GetQueueMessages();

            Assert.IsTrue(msgs == null || msgs.Count() == 0);

            int         numMsgs  = 10;
            List <Task> promises = new List <Task>();

            for (int i = 0; i < numMsgs; i++)
            {
                promises.Add(manager.AddQueueMessage(new CloudQueueMessage(i.ToString())));
            }
            Task.WaitAll(promises.ToArray());
            Assert.AreEqual(numMsgs, await manager.GetApproximateMessageCount());

            msgs = new List <CloudQueueMessage>(await manager.GetQueueMessages(numMsgs));
            Assert.AreEqual(numMsgs, msgs.Count());
            Assert.AreEqual(numMsgs, await manager.GetApproximateMessageCount());

            promises = new List <Task>();
            foreach (var msg in msgs)
            {
                promises.Add(manager.DeleteQueueMessage(msg));
            }
            Task.WaitAll(promises.ToArray());
            Assert.AreEqual(0, await manager.GetApproximateMessageCount());
        }
示例#2
0
        public async Task <IEnumerable <IBatchContainer> > GetQueueMessagesAsync()
        {
            try
            {
                var task = queue.GetQueueMessages();
                outstandingTask = task;
                CloudQueueMessage[] messages = (await task).ToArray();
                if (!messages.Any())
                {
                    return(Enumerable.Empty <IBatchContainer>());
                }

                AzureQueueBatchContainer[] azureQueueMessages = messages
                                                                .Select(msg => AzureQueueBatchContainer.FromCloudQueueMessage(msg, lastReadMessage++)).ToArray();

                outstandingTask = Task.WhenAll(messages.Select(queue.DeleteQueueMessage));
                await outstandingTask;

                return(azureQueueMessages);
            }
            finally
            {
                outstandingTask = null;
            }
        }
示例#3
0
        public async Task <IList <IBatchContainer> > GetQueueMessagesAsync(int maxCount)
        {
            try
            {
                int count = maxCount < 0 || maxCount == QueueAdapterConstants.UNLIMITED_GET_QUEUE_MSG ?
                            CloudQueueMessage.MaxNumberOfMessagesToPeek : Math.Min(maxCount, CloudQueueMessage.MaxNumberOfMessagesToPeek);

                var task = queue.GetQueueMessages(count);
                outstandingTask = task;
                IEnumerable <CloudQueueMessage> messages = await task;

                List <IBatchContainer> azureQueueMessages = messages
                                                            .Select(msg => (IBatchContainer)AzureQueueBatchContainer.FromCloudQueueMessage(msg, lastReadMessage++)).ToList();

                if (azureQueueMessages.Count == 0)
                {
                    return(azureQueueMessages);
                }

                outstandingTask = Task.WhenAll(messages.Select(queue.DeleteQueueMessage));
                await outstandingTask;

                return(azureQueueMessages);
            }
            finally
            {
                outstandingTask = null;
            }
        }