Esempio n. 1
0
        /// <summary>
        /// Creates a cloud queue message from stream event data.
        /// </summary>
        public CloudQueueMessage ToCloudQueueMessage <T>(Guid streamGuid, string streamNamespace, IEnumerable <T> events, Dictionary <string, object> requestContext)
        {
            var azureQueueBatchMessage = new AzureQueueBatchContainer(streamGuid, streamNamespace, events.Cast <object>().ToList(), requestContext);
            var rawBytes = this.serializationManager.SerializeToByteArray(azureQueueBatchMessage);

            //new CloudQueueMessage(byte[]) not supported in netstandard, taking a detour to set it
            var cloudQueueMessage = new CloudQueueMessage(null as string);

            cloudQueueMessage.SetMessageContent(rawBytes);
            return(cloudQueueMessage);
        }
Esempio n. 2
0
        public async Task QueueMessageBatchAsync <T>(Guid streamGuid, String streamNamespace, IEnumerable <T> events)
        {
            var queueId = streamQueueMapper.GetQueueForStream(streamGuid);
            AzureQueueDataManager queue;

            if (!Queues.TryGetValue(queueId, out queue))
            {
                var tmpQueue = new AzureQueueDataManager(queueId.ToString(), DeploymentId, DataConnectionString);
                await tmpQueue.InitQueueAsync();

                queue = Queues.GetOrAdd(queueId, tmpQueue);
            }
            var cloudMsg = AzureQueueBatchContainer.ToCloudQueueMessage(streamGuid, streamNamespace, events);
            await queue.AddQueueMessage(cloudMsg);
        }
Esempio n. 3
0
        public async Task QueueMessageBatchAsync <T>(Guid streamGuid, String streamNamespace, IEnumerable <T> events, StreamSequenceToken token, Dictionary <string, object> requestContext)
        {
            if (token != null)
            {
                throw new ArgumentException("AzureQueue stream provider currebtly does not support non-null StreamSequenceToken.", "token");
            }
            var queueId = streamQueueMapper.GetQueueForStream(streamGuid, streamNamespace);
            AzureQueueDataManager queue;

            if (!Queues.TryGetValue(queueId, out queue))
            {
                var tmpQueue = new AzureQueueDataManager(queueId.ToString(), DeploymentId, DataConnectionString);
                await tmpQueue.InitQueueAsync();

                queue = Queues.GetOrAdd(queueId, tmpQueue);
            }
            var cloudMsg = AzureQueueBatchContainer.ToCloudQueueMessage(streamGuid, streamNamespace, events, requestContext);
            await queue.AddQueueMessage(cloudMsg);
        }
        public async Task <IList <IBatchContainer> > GetQueueMessagesAsync(int maxCount)
        {
            try
            {
                var queueRef = queue; // store direct ref, in case we are somehow asked to shutdown while we are receiving.
                if (queueRef == null)
                {
                    return(new List <IBatchContainer>());
                }

                int count = maxCount < 0 || maxCount == QueueAdapterConstants.UNLIMITED_GET_QUEUE_MSG ?
                            CloudQueueMessage.MaxNumberOfMessagesToPeek : Math.Min(maxCount, CloudQueueMessage.MaxNumberOfMessagesToPeek);

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

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

                return(azureQueueMessages);
            }
            finally
            {
                outstandingTask = null;
            }
        }
Esempio n. 5
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;
            }
        }
Esempio n. 6
0
 internal static CloudQueueMessage ToCloudQueueMessage<T>(Guid streamGuid, String streamNamespace, IEnumerable<T> events, Dictionary<string, object> requestContext)
 {
     var azureQueueBatchMessage = new AzureQueueBatchContainer(streamGuid, streamNamespace, events.Cast<object>().ToList(), requestContext);
     var rawBytes = SerializationManager.SerializeToByteArray(azureQueueBatchMessage);
     return new CloudQueueMessage(rawBytes);
 }