从 Azure Function 中出列 Azure 存储队列

我一直在寻找示例来轻松地使 Azure 存储队列出队,就像将项目入队一样(通过在 Run 方法中注入 IAsyncCollector)。但遗憾的是,没有成功。我发现的唯一的事情就是将项目排队或对添加到队列中的项目做出反应。

我的本地服务器上运行一个应用程序,它将定期调用该函数(并不断调用直到队列为空)以获取队列的项目。我想使用 Azure 函数来执行此操作。

欢迎任何帮助。


有只小跳蛙
浏览 36回答 2
2回答

拉风的咖菲猫

如下:ICollector 和 IAsyncCollector 可用作存储队列输出绑定的参数类型。目前,azure 函数绑定仅支持输出绑定以将消息写入队列。或者,如果您不需要使用 HTTP 请求调用队列触发器,则可以使用队列触发器来检索消息。如果您必须使用 HTTP 请求,假设您必须创建一个 HTTP 触发函数,然后检索并删除队列以实现出队操作,如下面的代码。public static async Task<IActionResult> Run(        [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,        ILogger log)    {        log.LogInformation("C# HTTP trigger function processed a request.");        // Parse the connection string and return a reference to the storage account.        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("AzureWebJobsStorage"));        CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();        // Retrieve a reference to a queue        CloudQueue queue = queueClient.GetQueueReference("myqueue");        // Async dequeue the message        CloudQueueMessage retrievedMessage = await queue.GetMessageAsync();        Console.WriteLine("Retrieved message with content '{0}'", retrievedMessage.AsString);        //Process the message in less than 30 seconds, and then delete the message        await queue.DeleteMessageAsync(retrievedMessage);        return  (ActionResult)new OkObjectResult(retrievedMessage.AsString);    }

SMILET

为什么不创建一个应用程序调用的 Webhook 函数,然后在该函数中,您可以根据需要使用适用于您使用的任何语言的标准存储队列 API 将项目出列。
打开App,查看更多内容
随时随地看视频慕课网APP