当前位置: 首页>>代码示例>>C#>>正文


C# CloudQueue.AddMessageAsync方法代码示例

本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Queue.CloudQueue.AddMessageAsync方法的典型用法代码示例。如果您正苦于以下问题:C# CloudQueue.AddMessageAsync方法的具体用法?C# CloudQueue.AddMessageAsync怎么用?C# CloudQueue.AddMessageAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.WindowsAzure.Storage.Queue.CloudQueue的用法示例。


在下文中一共展示了CloudQueue.AddMessageAsync方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateEnqueuedMessageAsync

        private static async Task UpdateEnqueuedMessageAsync(CloudQueue queue)
        {
            Console.WriteLine("5. Insert another test message ");
            await queue.AddMessageAsync(new CloudQueueMessage("Hello World Again!"));

            Console.WriteLine("6. Change the contents of a queued message");
            CloudQueueMessage message = await queue.GetMessageAsync();

            message.SetMessageContent("Updated contents.");
            await queue.UpdateMessageAsync(message, TimeSpan.Zero, MessageUpdateFields.Content | MessageUpdateFields.Visibility);
        }
开发者ID:techieshravan,项目名称:azure,代码行数:11,代码来源:Program.cs

示例2: BasicQueueOperationsAsync

        private static async Task BasicQueueOperationsAsync(CloudQueue queue)
        {
            Console.WriteLine("2. Insert a single message into a queue");

            await queue.AddMessageAsync(new CloudQueueMessage("Hello World!"));

            Console.WriteLine("3. Peek at the next message");
            CloudQueueMessage peekedMessage = await queue.PeekMessageAsync();

            if (peekedMessage != null)
            {
                Console.WriteLine("The peeked message is: {0}", peekedMessage.AsString);
            }

            Console.WriteLine("4. De-queue the next message");
            CloudQueueMessage message = await queue.GetMessageAsync();
            if (message != null)
            {
                Console.WriteLine("Processing & deleting message with content: {0}", message.AsString);
                await queue.DeleteMessageAsync(message);
            }
        }
开发者ID:techieshravan,项目名称:azure,代码行数:22,代码来源:Program.cs

示例3: UpdateQueueSASTestAsync

        public async Task UpdateQueueSASTestAsync()
        {
            CloudQueueClient client = GenerateCloudQueueClient();
            CloudQueue queue = client.GetQueueReference(GenerateNewQueueName());

            try
            {
                await queue.CreateAsync();
                string messageContent = Guid.NewGuid().ToString();
                CloudQueueMessage message = new CloudQueueMessage(messageContent);
                await queue.AddMessageAsync(message);
                SharedAccessQueuePolicy policy = new SharedAccessQueuePolicy()
                {
                    SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5),
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30),
                    Permissions = SharedAccessQueuePermissions.Add | SharedAccessQueuePermissions.ProcessMessages,
                };
                string id = Guid.NewGuid().ToString();
                string sasToken = queue.GetSharedAccessSignature(policy, null);

                StorageCredentials sasCreds = new StorageCredentials(sasToken);
                CloudQueue sasQueue = new CloudQueue(queue.Uri, sasCreds);
                OperationContext context = new OperationContext();

                await TestHelper.ExpectedExceptionAsync(
                    async () => await sasQueue.PeekMessageAsync(null, context),
                    context,
                    "Peek when Sas does not allow Read access on the queue",
                    HttpStatusCode.Forbidden);

                await sasQueue.AddMessageAsync(message);

                SharedAccessQueuePolicy policy2 = new SharedAccessQueuePolicy()
                {
                    SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5),
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30),
                    Permissions = SharedAccessQueuePermissions.Add | SharedAccessQueuePermissions.ProcessMessages | SharedAccessQueuePermissions.Read,
                };

                string sasToken2 = queue.GetSharedAccessSignature(policy2, null);
                sasCreds.UpdateSASToken(sasToken2);
                sasQueue = new CloudQueue(queue.Uri, sasCreds);

                await sasQueue.PeekMessageAsync();
            }
            finally
            {
                queue.DeleteIfExistsAsync().AsTask().Wait();
            }
        }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:50,代码来源:CloudQueueTest.cs

示例4: SendQueueAsync

        /// <summary>
        /// 
        /// </summary>
        /// <param name="i"></param>
        /// <param name="esLog"></param>
        /// <param name="queue"></param>
        /// <param name="message"></param>
        /// <returns></returns>

        private async Task SendQueueAsync(int i, ELSLogs esLog, CloudQueue queue, string message)
        {
            if (!_queueError)
            //create, fufill and send message
            {

                await queue.AddMessageAsync(new CloudQueueMessage(message));
            }
            else
            {

                _cache.ListLeftPush("s", message);
            }

        }
开发者ID:tzkwizard,项目名称:ELS,代码行数:24,代码来源:TestLogHandler.cs

示例5: AddMessagesAsync

        /// <inheritdoc />
        public async Task AddMessagesAsync(CloudQueue queue, IEnumerable<CloudQueueMessage> messages)
        {
            if (queue == null)
            {
                throw new ArgumentNullException(nameof(queue));
            }

            try
            {
                List<Task> addTasks = new List<Task>();
                foreach (var message in messages)
                {
                    Task addTask = queue.AddMessageAsync(message);
                    addTasks.Add(addTask);
                }

                await Task.WhenAll(addTasks);
            }
            catch (Exception ex)
            {
                string errorMessage = GetStorageErrorMessage(ex);
                int statusCode = GetStorageStatusCode(ex);
                string msg = string.Format(CultureInfo.CurrentCulture, AzureStorageResources.StorageManager_OperationFailed, statusCode, errorMessage);
                _logger.Error(msg, ex);
            }
        }
开发者ID:aspnet,项目名称:WebHooks,代码行数:27,代码来源:StorageManager.cs

示例6: ProcessBatchOfMessagesAsync

        /// <summary>
        /// Demonstrate adding a number of messages, checking the message count and batch retrieval of messages. During retrieval we 
        /// also set the visibility timeout to 5 minutes. Visibility timeout is the amount of time message is not visible to other 
        /// clients after a GetMessageOperation assuming DeleteMessage is not called. 
        /// </summary>
        /// <param name="queue">The sample queue</param>
        private static async Task ProcessBatchOfMessagesAsync(CloudQueue queue)
        {
            // Enqueue 20 messages by which to demonstrate batch retrieval
            Console.WriteLine("7. Enqueue 20 messages.");
            for (int i = 0; i < 20; i++)
            {
                await queue.AddMessageAsync(new CloudQueueMessage(string.Format("{0} - {1}", i, "Hello World")));
            }

            // The FetchAttributes method asks the Queue service to retrieve the queue attributes, including an approximation of message count 
            Console.WriteLine("8. Get the queue length");
            queue.FetchAttributes();
            int? cachedMessageCount = queue.ApproximateMessageCount;
            Console.WriteLine("Number of messages in queue: {0}", cachedMessageCount);

            // Dequeue a batch of 21 messages (up to 32) and set visibility timeout to 5 minutes. Note we are dequeuing 21 messages because the earlier
            // UpdateEnqueuedMessage method left a message on the queue hence we are retrieving that as well. 
            Console.WriteLine("9. Dequeue 21 messages, allowing 5 minutes for the clients to process.");
            foreach (CloudQueueMessage msg in await queue.GetMessagesAsync(21, TimeSpan.FromMinutes(5), null, null))
            {
                Console.WriteLine("Processing & deleting message with content: {0}", msg.AsString);

                // Process all messages in less than 5 minutes, deleting each message after processing.
                await queue.DeleteMessageAsync(msg);
            }
        }
开发者ID:tamram,项目名称:storage-queue-dotnet-getting-started,代码行数:32,代码来源:Program.cs

示例7: UpdateEnqueuedMessageAsync

        /// <summary>
        /// Update an enqueued message and its visibility time. For workflow scenarios this could enable you to update 
        /// the status of a task as well as extend the visibility timeout in order to provide more time for a client 
        /// continue working on the message before another client can see the message. 
        /// </summary>
        /// <param name="queue">The sample queue</param>
        private static async Task UpdateEnqueuedMessageAsync(CloudQueue queue)
        {
            // Insert another test message into the queue 
            Console.WriteLine("5. Insert another test message ");
            await queue.AddMessageAsync(new CloudQueueMessage("Hello World Again!"));

            Console.WriteLine("6. Change the contents of a queued message");
            CloudQueueMessage message = await queue.GetMessageAsync();
            message.SetMessageContent("Updated contents.");
            await queue.UpdateMessageAsync(
                message,
                TimeSpan.Zero,  // For the purpose of the sample make the update visible immediately
                MessageUpdateFields.Content |
                MessageUpdateFields.Visibility);
        }
开发者ID:tamram,项目名称:storage-queue-dotnet-getting-started,代码行数:21,代码来源:Program.cs

示例8: AddMessages

 public Task AddMessages(CloudQueue queue, IEnumerable<string> messages)
 {
     return Task.WhenAll(messages.Select(m => queue.AddMessageAsync(new CloudQueueMessage(m))));
 }
开发者ID:abatishchev,项目名称:ab,代码行数:4,代码来源:AzureQueueClient.cs

示例9: AddMessage

 public Task AddMessage(CloudQueue queue, string message)
 {
     return queue.AddMessageAsync(new CloudQueueMessage(message));
 }
开发者ID:abatishchev,项目名称:ab,代码行数:4,代码来源:AzureQueueClient.cs

示例10: QueuePage

        private void QueuePage(Uri resourceUri, Uri itemType, int cantonCommitId, CloudQueue queue)
        {
            // mark that we sent a message for this
            _workQueueStatus.AddOrUpdate(cantonCommitId, true, (k,v) => true);

            JObject summary = new JObject();
            summary.Add("uri", resourceUri.AbsoluteUri);
            summary.Add("itemType", itemType.AbsoluteUri);
            summary.Add("submitted", DateTime.UtcNow.ToString("O"));
            summary.Add("failures", 0);
            summary.Add("host", Host);
            summary.Add("cantonCommitId", cantonCommitId);

            _queueTasks.Enqueue(queue.AddMessageAsync(new CloudQueueMessage(summary.ToString())));

            Log("Page Creation: Commit: " + cantonCommitId + " Uri: " + resourceUri.AbsoluteUri);
        }
开发者ID:jinujoseph,项目名称:NuGet.Services.Metadata,代码行数:17,代码来源:CatalogPageJob.cs

示例11: AddMessageAndCreateIfNotExistsAsync

        private static async Task AddMessageAndCreateIfNotExistsAsync(CloudQueue queue, CloudQueueMessage message, CancellationToken cancellationToken)
        {
            if (queue == null)
            {
                throw new ArgumentNullException("queue");
            }

            bool isQueueNotFoundException = false;
            try
            {
                await queue.AddMessageAsync(message, cancellationToken);
                return;
            }
            catch (StorageException exception)
            {
                if (!exception.IsNotFoundQueueNotFound())
                {
                    throw;
                }

                isQueueNotFoundException = true;
            }

            Debug.Assert(isQueueNotFoundException);
            await queue.CreateIfNotExistsAsync(cancellationToken);
            await queue.AddMessageAsync(message, cancellationToken);
        }
开发者ID:Bjakes1950,项目名称:azure-webjobs-sdk,代码行数:27,代码来源:QueueProcessor.cs

示例12: EnqueueCore

        private static async Task EnqueueCore(CloudQueue queue, DateTimeKey buildStateKey, BoundBuildId buildId, TimeSpan? delay, CancellationToken cancellationToken)
        {
            // Enqueue a message to process the build.  Insert a delay if the build isn't finished yet so that 
            // we don't unnecessarily ask Jenkins for information.
            var buildMessage = new BuildStateMessage()
            {
                BuildStateKeyRaw = buildStateKey.Key,
                BuildNumber = buildId.Number,
                HostRaw = buildId.Host.ToString(),
                JobName = buildId.JobName
            };

            var queueMessage = new CloudQueueMessage(JsonConvert.SerializeObject(buildMessage));
            await queue.AddMessageAsync(
                queueMessage, 
                timeToLive: null, 
                initialVisibilityDelay: delay, 
                options: null, 
                operationContext: null, 
                cancellationToken: cancellationToken);
        }
开发者ID:jaredpar,项目名称:jenkins,代码行数:21,代码来源:StateUTil.cs

示例13: SendQueueAsync

        private async Task SendQueueAsync(CloudQueue queue, string message, bool flag)
        {
            if (!flag)
            //create, fufill and send message
            {

                await queue.AddMessageAsync(new CloudQueueMessage(message));
            }
            else
            {

                await _cache.ListLeftPushAsync("s", message);
            }

        }
开发者ID:tzkwizard,项目名称:Azure,代码行数:15,代码来源:QueueService.cs


注:本文中的Microsoft.WindowsAzure.Storage.Queue.CloudQueue.AddMessageAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。