Exemple #1
0
        public Task EnqueueAsync(T item, IDictionary <string, object> messageProperties = null)
        {
            if (messageProperties != null)
            {
                throw new NotSupportedException("Message properties are not supported by Azure Storage queues");
            }

            _logger?.LogTrace("AsyncQueue: EnqueueAsync - enqueueing item");
            CloudQueueMessage message = new CloudQueueMessage(_serializer.Serialize(item));

            return(_queue.AddMessageAsync(message));
        }
Exemple #2
0
        private async Task DoEnqueue(T item, TimeSpan?initialVisibilityDelay)
        {
            string serializedItem = _serializer.Serialize(item);
            string blobname       = $"{Guid.NewGuid()}.que";

            try
            {
                using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(serializedItem)))
                {
                    await _blobRepository.UploadAsync(blobname, stream);
                }
            }
            catch (Exception ex)
            {
                throw new LargeMessageQueueException("Unable to upload blob to blob store. No item queued.", ex, blobname);
            }

            try
            {
                if (initialVisibilityDelay.HasValue)
                {
                    await _referenceQueue.EnqueueAsync(new LargeMessageReference
                    {
                        BlobReference = blobname
                    }, initialVisibilityDelay.Value);
                }
                else
                {
                    await _referenceQueue.EnqueueAsync(new LargeMessageReference
                    {
                        BlobReference = blobname
                    });
                }
            }
            catch (Exception ex)
            {
                throw new LargeMessageQueueException("Error enqueuing item, blob may be orphaned", ex, blobname);
            }
        }