简体   繁体   中英

Windows Azure Queue - CloudQueue.GetMessage() not working for latest version of Microsoft.WindowsAzure.Storage (v5.0.0)

I'm new to Azure and trying out the tutorial here .

The tutorial is about creating a Cloud Service on Azure taking advantage of the Web Role delegating task to the Worker Role. The only part that matters; when user uploads an image to the Web Role, the Web Role will put the image in Azure Storage and create a new record in the database with a field containing the URL of the stored image. The Web Role next places a message (the ID of the newly added record) in Azure Queue.

var queueMessage = new CloudQueueMessage(id);
await _cloudQueue.AddMessageAsync(queueMessage);

The Worker Role will then retrieve the message from the queue. Next, retrieve the record from the database. Then create a thumbnail from the image url of the retrieved database record.

while (true) {
    var msg = _cloudQueue.GetMessage();
    if (msg != null) {
        CreateThumbnail();
    }

    System.Threading.Thread.Sleep(1000);
}

The tutorial offers guidance to

  1. download the solution source files and open from Visual Studio
  2. or create the solution from scratch using Visual Studio

The solution works fine when using the downloaded source files. In the Worker Role, var msg = _cloudQueue.GetMessage(); .

msg always has something (not null) albeit there's a delay of 3 to 4 seconds after the image is uploaded. Therefore CreateThumbnail() is always executed 3 to 4 seconds after the image is uploaded.

However, if I were to create the solution from scratch, msg is always null no matter how long I waited and CreateThumbnail was never executed. I made sure the Worker Role was indeed running by putting breakpoint here and there.

The source of the problem

After a few painstaking hours, I have boiled the problem down to the assembly Microsoft.WindowsAzure.Storage . The solution source files downloaded from the tutorial page is using version 3.2.0 while the solution created from scratch is using the latest version 5.0.0 from NuGet. So in order words, msg is always null if I'm using the latest version 5.0.0 of Microsoft.WindowsAzure.Storage on the Worker Role. Is this a known issue or am I missing something.

I'm sorry you've had difficulty getting this tutorial to work. I've checked with the owner of the tutorial, and it's been recently updated (around 9/1). Please download the new version of the Visual Studio solution and try it again.

There are a few things to keep in mind, which are outlined in the troubleshooting section of the tutorial:

  • Change the startup project to ContosoAdsCloudService
  • Run Visual Studio as an administrator, and specify that the solution should run with the full compute emulator instead of the express emulator.

From the tutorial:

By default new cloud service projects use the Azure compute emulator express to simulate the Azure environment. This is a lightweight version of the full compute emulator, and under some conditions the full emulator will work when the express version does not.

To change the project to use the full emulator, right-click the ContosoAdsCloudService project, and then click Properties. In the Properties window click the Web tab, and then click the Use Full Emulator radio button.

In order to run the application with the full emulator, you have to open Visual Studio with administrator privileges.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM