[英]Microsoft.WindowsAzure.Storage.StorageException: The remote server returned an error: (404) Not Found
I am receiving this error in my worker role: 我在我的工作角色中收到此错误:
Microsoft.WindowsAzure.Storage.StorageException: The remote server returned an error: (404) Not Found. ---> System.Net.WebException: The remote server returned an error: (404) Not Found. at System.Net.HttpWebRequest.GetResponse() at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](StorageCommandBase`1 cmd, IRetryPolicy policy, OperationContext operationContext) --- End of inner exception stack trace --- at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](StorageCommandBase`1 cmd, IRetryPolicy policy, OperationContext operationContext) at Microsoft.WindowsAzure.Storage.Queue.CloudQueue.DeleteMessage(String messageId, String popReceipt, QueueRequestOptions options, OperationContext operationContext) at Microsoft.WindowsAzure.Storage.Queue.CloudQueue.DeleteMessage(CloudQueueMessage message, QueueRequestOptions options, OperationContext operationContext) at CloudCartConnector.TaskRole2.WorkerRole.ExecuteTask() in C:\a\src\CCC\Source\CloudCartConnector.TaskRole2\WorkerRole.cs:line 101 Request Information RequestID:7a7c08ec-0003-0059-6d7b-2d118f000000 RequestDate:Thu, 03 Dec 2015 03:33:11 GMT StatusMessage:The specified queue does not exist. ErrorCode:QueueNotFound
If there was an exception in the on start method, would this cause a worker role to fail to run? 如果on start方法中存在异常,是否会导致worker角色无法运行? Should I enter a try catch statement in the on start method and just return base.OnStart()? 我应该在on start方法中输入try catch语句并返回base.OnStart()吗? If my storage accounts becomes unavailable, due to a MS upgrade or a server going down, is the try catch the best? 如果我的存储帐户因MS升级或服务器关闭而变得不可用,那么try是最好的吗?
public override bool OnStart()
{
ServicePointManager.DefaultConnectionLimit = 12;
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
// Create the queue client.
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
// Retrieve a reference to a queue.
queue = queueClient.GetQueueReference("taskqueue");
return base.OnStart();
}
Below this code, I execute a task. 在这段代码下面,我执行一个任务。 Should I say if the queue is null, just return? 如果队列为空,我应该说回来吗?
public string GetTasks()
{
CloudQueueMessage cloudQueueMessasge = new CloudQueueMessage(message);
queue.AddMessage(cloudQueueMessasge, new TimeSpan(0, 30, 0));
}
catch (Exception ex)
{
return ex.ToString();
}
}
You should have a try...catch
block in your OnStart method. 您应该在OnStart方法中使用try...catch
块。
try{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
// Create the queue client.
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
// Retrieve a reference to a queue.
queue = queueClient.GetQueueReference("taskqueue");
}
catch(Microsoft.WindowsAzure.Storage.StorageException e)
{
// Exception Handling & Logging
// Return false for OnStart
}
You should also check if queue is null in your GetTasks()
method to prevent throwing potential and unnecessary NullReferenceException. 您还应该检查GetTasks()
方法中队列是否为null,以防止抛出潜在的和不必要的NullReferenceException。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.