Пример #1
0
        public async Task QueueMessageBatchAsync <T>(Guid streamGuid, string streamNamespace, IEnumerable <T> events, StreamSequenceToken token, Dictionary <string, object> requestContext)
        {
            QueueId         queueId;
            MemoryEventData eventData;

            try
            {
                queueId   = streamQueueMapper.GetQueueForStream(streamGuid, streamNamespace);
                eventData = MemoryBatchContainer.ToMemoryEventData(streamGuid, streamNamespace, events, requestContext);
                IMemoryStreamQueueGrain queueGrain = GetQueueGrain(queueId);
                await queueGrain.Enqueue(eventData);
            }
            catch (Exception exc)
            {
                logger.Error((int)ProviderErrorCode.MemoryStreamProviderBase_QueueMessageBatchAsync, "Exception thrown in MemoryAdapterFactory.QueueMessageBatchAsync.", exc);
                throw;
            }
        }
        public async Task <IList <IBatchContainer> > GetQueueMessagesAsync(int maxCount)
        {
            IEnumerable <MemoryEventData>  eventData;
            List <IBatchContainer>         batches;
            Task <List <MemoryEventData> > task = null;

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