更新云队列中的邮件内容时出现异常

时间:2012-09-02 20:06:35

标签: c# azure message-queue azure-storage azure-worker-roles

我在尝试更新云队列上的消息时遇到异常。

例外是:

System.ArgumentNullException was unhandled
  Message=Value cannot be null.
Parameter name: messageId
  Source=Microsoft.WindowsAzure.StorageClient
  ParamName=messageId
  StackTrace:
       at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.get_Result()
       at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.ExecuteAndWait()
       at Microsoft.WindowsAzure.StorageClient.TaskImplHelper.ExecuteImplWithRetry(Func`1 impl, RetryPolicy policy)
       at Microsoft.WindowsAzure.StorageClient.CloudQueue.UpdateMessage(CloudQueueMessage message, TimeSpan visibilityTimeout, MessageUpdateFields updateFields)
       at WorkerRole.WorkerRole.DoTask(Task task) in C:\Users\ALICE\Desktop\Diplloma\AG - Copy\AzureGrid\WorkerRole\WorkerRole.cs:line 133
       at WorkerRole.WorkerRole.Run() in C:\Users\ALICE\Desktop\Diplloma\AG - Copy\AzureGrid\WorkerRole\WorkerRole.cs:line 51
       at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.StartRoleInternal()
       at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.StartRole()
       at Microsoft.WindowsAzure.ServiceRuntime.Implementation.Loader.RoleRuntimeBridge.<StartRole>b__1()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

我的代码是:

private void DoTask(Task task)
{
    CloudQueueMessage resultsMessage;

    // Queue a status message to indicate this worker is starting the task.
    task.TaskStatus = Task.Status.Running;
    task.Worker = System.Net.Dns.GetHostName();
    resultsMessage = task.Message;
    ResultsQueue.UpdateMessage(resultsMessage, TimeSpan.FromSeconds(QueueTimeout), MessageUpdateFields.Content | MessageUpdateFields.Visibility);


    Trace.WriteLine("Executing task " + task.TaskId.ToString() + " for job " + task.JobId + ", project " + task.ProjectName,"Information");

    using (GridWorker gridWorker = new AppWorker())
    {
        gridWorker.Execute(task);
    }

    // Queue results.
    task.TaskStatus = Task.Status.Complete;
    resultsMessage = task.Message;
    ResultsQueue.UpdateMessage(resultsMessage, TimeSpan.FromSeconds(QueueTimeout), MessageUpdateFields.Content | MessageUpdateFields.Visibility);
}

以下是创建任务对象的方法

public override void Run()
{
    CloudQueueMessage taskMessage;
    Task task;

    // This is a sample worker implementation. Replace with your logic.
    Trace.WriteLine("Initializing", "Information");

    LoadConfigurationSettings();
    OpenQueues();

    Trace.WriteLine("Initializing", "Ready for work");

    // Work loop. Read a task from the queue. If there is a task, execute it and pass work output to the results queue. Loop.

    while (true)
    {
        taskMessage = TaskQueue.GetMessage(TimeSpan.FromSeconds(QueueTimeout));
        //taskMessage = TaskQueue.PeekMessage();

        if (taskMessage != null)
        {
            task = new Task(taskMessage);
            DoTask(task);
            TaskQueue.DeleteMessage(taskMessage);
        }
        else
            Thread.Sleep(SleepInterval * 1000);
    }
}

这是我的第一个申请,我不明白该怎么做。

1 个答案:

答案 0 :(得分:2)

task.Message来自哪里?以前是从队列中读取的吗? (似乎缺少消息ID。)