コード例 #1
0
        public async Task <IList <IBatchContainer> > GetQueueMessagesAsync(int maxCount)
        {
            var watch = Stopwatch.StartNew();
            List <IBatchContainer>           batches;
            Task <List <MemoryMessageData> > task = null;

            try
            {
                task = queueGrain.Dequeue(maxCount);
                awaitingTasks.Add(task);
                var eventData = await task;
                batches = eventData.Select(data => new MemoryBatchContainer <TSerializer>(data, this.serializer)).ToList <IBatchContainer>();
                watch.Stop();
                this.receiverMonitor?.TrackRead(true, watch.Elapsed, null);
                if (eventData.Count > 0)
                {
                    var oldestMessage = eventData[0];
                    var newestMessage = eventData[eventData.Count - 1];
                    this.receiverMonitor?.TrackMessagesReceived(eventData.Count(), oldestMessage.EnqueueTimeUtc, newestMessage.EnqueueTimeUtc);
                }
            }
            catch (Exception exc)
            {
                logger.Error((int)ProviderErrorCode.MemoryStreamProviderBase_GetQueueMessagesAsync, "Exception thrown in MemoryAdapterFactory.GetQueueMessagesAsync.", exc);
                watch.Stop();
                this.receiverMonitor?.TrackRead(true, watch.Elapsed, exc);
                throw;
            }
            finally
            {
                awaitingTasks.Remove(task);
            }
            return(batches);
        }
コード例 #2
0
        public async Task <IList <IBatchContainer> > GetQueueMessagesAsync(int maxCount)
        {
            List <IBatchContainer>           batches;
            Task <List <MemoryMessageData> > task = null;

            try
            {
                task = queueGrain.Dequeue(maxCount);
                awaitingTasks.Add(task);
                IEnumerable <MemoryMessageData> eventData = await task;
                batches = eventData.Select(data => new MemoryBatchContainer <TSerializer>(data)).ToList <IBatchContainer>();
            }
            catch (Exception exc)
            {
                logger.Error((int)ProviderErrorCode.MemoryStreamProviderBase_GetQueueMessagesAsync, "Exception thrown in MemoryAdapterFactory.GetQueueMessagesAsync.", exc);
                throw;
            }
            finally
            {
                awaitingTasks.Remove(task);
            }
            return(batches);
        }