gpt4 book ai didi

c# - 如何等待 Azure CloudQueue 被删除?

转载 作者:行者123 更新时间:2023-12-02 06:09:50 25 4
gpt4 key购买 nike

我正在运行一些使用 Azure CloudQueue 的测试,并且作为设置/拆卸,我正在调用 CreateIfNotExistsAsync()DeleteIfExistsAsync() 。但是,当我连续运行测试时,出现 Microsoft.WindowsAzure.Storage.StorageException,“远程服务器返回错误:(409) 冲突。”

    await cloudQueue.CreateIfNotExistsAsync();
// do work 1
await cloudQueue.DeleteIfExistsAsync();
await cloudQueue.CreateIfNotExistsAsync(); // throws exception
// do work 2

仔细查看服务器的响应后,我发现 StatusDescription 表示“正在删除指定的队列。”

是否有一种方法可以调用,以便一旦返回,我就可以确定队列已被删除?

================================================== =========================更新现在我想起来了。如果Azure队列服务器想要回复删除结果,它必须跟踪未完成的传入请求,这显然是糟糕的设计(容易受到DOS攻击)...

最佳答案

Is there a method that I can call so that once it returns, I know for sure the queue is already deleted?

不幸的是没有。删除队列(或 blob 容器/表/文件共享)是异步操作。当您发送删除队列的请求时,Azure 存储会将该队列标记为删除(以便无法对其执行任何操作),然后通过后台进程实际删除该队列。根据文档,删除队列最多可能需要 30 秒。但是,这可能更多地取决于其中保存的数据量。

来自documentation :

When a queue is successfully deleted, the queue is immediately marked for deletion and is no longer accessible to clients. The queue is later removed from the Queue service during garbage collection.

可能的解决方法:

由于您无法调用任何方法来确定队列已被删除,因此您需要做的是尝试使用 CreateIfNotExistsAsync 创建队列并捕获任何错误。如果 HTTP 状态代码为 Conflict (409) 并且错误代码为 QueueBeingDeleted,您应该等待一段时间,然后重试该操作。如果需要,您可以在重试之间设置增量延迟。

关于c# - 如何等待 Azure CloudQueue 被删除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46837562/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com