示例#1
0
        /// <summary>
        /// Deletes the specified queue.
        /// </summary>
        /// <param name="queueName">The name of the queue to be deleted.</param>
        /// <returns>True if the queue name has been actually deleted, otherwise False.</returns>
        public bool DeleteQueue(string queueName)
        {
            Guard.ArgumentNotNullOrEmptyString(queueName, "queueName");

            var callToken = TraceManager.CloudStorageComponent.TraceIn(queueName);

            try
            {
                // Must delete the associated blob storage in which large messages are persisted.
                LargeQueueMessageInfo largeMsgInfo = LargeQueueMessageInfo.Create(queueName);
                this.overflowStorage.DeleteContainer(largeMsgInfo.ContainerName);

                // Now proceed with deleting the queue.
                var queue = this.queueStorage.GetQueueReference(CloudUtility.GetSafeContainerName(queueName));

                return(this.retryPolicy.ExecuteAction <bool>(() =>
                {
                    if (queue.Exists())
                    {
                        queue.Delete();
                        return true;
                    }
                    return false;
                }));
            }
            catch (Exception ex)
            {
                TraceManager.CloudStorageComponent.TraceError(ex);
                return(false);
            }
            finally
            {
                TraceManager.CloudStorageComponent.TraceOut(callToken);
            }
        }
示例#2
0
        /// <summary>
        /// Puts a single message on a queue.
        /// </summary>
        /// <typeparam name="T">The type of the payload associated with the message.</typeparam>
        /// <param name="queueName">The target queue name on which message will be placed.</param>
        /// <param name="message">The payload to be put into a queue.</param>
        public void Put <T>(string queueName, T message)
        {
            Guard.ArgumentNotNullOrEmptyString(queueName, "queueName");
            Guard.ArgumentNotNull(message, "message");

            // Obtain a reference to the queue by its name. The name will be validated against compliance with storage resource names.
            var queue = this.queueStorage.GetQueueReference(CloudUtility.GetSafeContainerName(queueName));

            CloudQueueMessage queueMessage = null;

            // Allocate a memory buffer into which messages will be serialized prior to being put on a queue.
            using (MemoryStream dataStream = new MemoryStream(Convert.ToInt32(CloudQueueMessage.MaxMessageSize)))
            {
                // Perform serialization of the message data into the target memory buffer.
                this.dataSerializer.Serialize(message, dataStream);

                // Reset the position in the buffer as we will be reading its content from the beginning.
                dataStream.Seek(0, SeekOrigin.Begin);

                // First, determine whether the specified message can be accommodated on a queue.
                if (CloudUtility.IsAllowedQueueMessageSize(dataStream.Length))
                {
                    queueMessage = new CloudQueueMessage(dataStream.ToArray());
                }
                else
                {
                    // Create an instance of a large queue item metadata message.
                    LargeQueueMessageInfo queueMsgInfo = LargeQueueMessageInfo.Create(queueName);

                    // Persist the stream of data that represents a large message into the overflow message store.
                    this.overflowStorage.Put <Stream>(queueMsgInfo.ContainerName, queueMsgInfo.BlobReference, dataStream);

                    // Invoke the Put operation recursively to enqueue the metadata message.
                    Put <LargeQueueMessageInfo>(queueName, queueMsgInfo);
                }
            }

            // Check if a message is available to be put on a queue.
            if (queueMessage != null)
            {
                Put(queue, queueMessage);
            }
        }