Skip to content Skip to sidebar Skip to footer

Accessing Windows Azure Queues From Client Side Javascript/jquery

For a UI feature, I need to read from a Windows Azure queue and update the UI accordingly. I see plenty of node.js examples, but nothing using pure Javascript or Jquery. (azureQue

Solution 1:

This isn't possible directly from the browser. JavaScript in the browser has to follow the same-origin policy, which means that JavaScript can only make calls to the domain of the current web page. Since your web page won't be served from <account>.queue.windows.net, it means your JavaScript won't be able to call APIs on that domain. (This would be possible in most browsers if the queue service served up CORS headers, but it doesn't.)

You'll need to host a web endpoint (in your MVC 4 app, probably) that proxies queue messages. Your JavaScript will send a message to your web app, and your web app will put the message on the queue.

Solution 2:

UPDATE: Please see comments below and discard this answer.

You can try fetching the list of messages using shared access signature (SAS) for queues. I just did a simple test where I created a SAS for queue with "Read" Permission. I get a URI something like this:

youraccount.core.queue.net/queuename?sv=2012-02-12&st=2012-10-11T04%3A31%3A53Z&se=2012-10-11T05%3A31%3A53Z&sp=raup&sig=PN4dyOoOIBlJPQbQ%2Bu7jDLyt%2FpIc3k2k1NZTei6q7Cg%3D

Using this I created a URI for peeking messages

youraccount.core.queue.net/queuename/messages?sv=2012-02-12&st=2012-10-11T04%3A31%3A53Z&se=2012-10-11T05%3A31%3A53Z&sp=r&sig=PN4dyOoOIBlJPQbQ%2Bu7jDLyt%2FpIc3k2k1NZTei6q7Cg%3D&peekonly=true

I then used this URI in my JavaScript code and traced the request in Fiddler. I was able to see response coming back from Windows Azure Storage.

Solution 3:

You can access Windows Azure Queue over REST interface using any supported language. With JavaScript your can make ajax calls to connect with Azure Storage Queue to read and write messages. Once you have JavaScript + Ajax based code in your hand, you just need to use Azure Queue Storage REST API to perform any operation.

Here is a sample using JavaScript to connect Azure Storage Queue. You can modify the code to connect to your real Azure Storage queue and it will fulfill your need:

Post a Comment for "Accessing Windows Azure Queues From Client Side Javascript/jquery"