2017-10-19 50 views
1

我正在运行一些使用Azure CloudQueue的测试,并且作为setup/teardown,我打电话给CreateIfNotExistsAsync()DeleteIfExistsAsync()。但是,当我将测试重新运行时,出现了Microsoft.WindowsAzure.Storage.StorageException,“远程服务器返回了错误:(409)冲突。”如何等待Azure CloudQueue被删除?

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

在服务器的响应左看右看之后,我找到了状态说明称“指定的队列中被删除。”

有没有一种方法可以调用,所以一旦它返回,我知道肯定队列已被删除?

============================================== =========================== UPDATE现在我想到了。如果Azure的队列服务器要与删除结果回复,就必须跟踪未完成的传入的请求,这显然是DESGIN不好(易受DOS攻击)的...

回答

1

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,则应等待一段时间并重试该操作。如果你愿意,你可以在重试之间增加延迟。