none
How to create a Azure queue using javascript

    Question

  • Hi Team,

    I am new to the Azure.

    How to create a queue in the azure using javascript?

    How to insert the message to the queue using javascript?

    Can you please share the sample code?

    Tuesday, May 17, 2016 6:42 AM

All replies

  • Hi,

    Thank you for posting here,

    To create a queue in the azure using java refer below link:

    https://azure.microsoft.com/en-gb/documentation/articles/storage-java-how-to-use-queue-storage/#how-to-create-a-queue

    To insert the message to the queue using java refer below link:

    https://azure.microsoft.com/en-gb/documentation/articles/storage-java-how-to-use-queue-storage/#how-to-add-a-message-to-a-queue

    Regards,

    Vikranth S.

    Please remember to click "Mark as Answer" on the post that helps you, this can be beneficial to other community members reading the thread. And Vote as Helpful.

    • Proposed as answer by Akampa Tuesday, May 17, 2016 3:03 PM
    Tuesday, May 17, 2016 2:44 PM
    Moderator
  • Thank you vikranth,

    But this solution refers to server side code.

    I want to create the azure storage queue using javascript.

    Tuesday, May 17, 2016 5:36 PM
  • Hi -

    All code for working with Azure queues is server-side code. Because Queue storage is a service running in Azure, you can only work with queues by making calls to the service.

    Node.js is the closest language to JavaScript. See here for node.js examples:

    https://azure.microsoft.com/en-us/documentation/articles/storage-nodejs-how-to-use-queues/ 

    Thursday, May 19, 2016 12:40 AM
  • Thank you Tamra Myers for reply.

    Yes, Queue storage is running in the azure.But we have the rest api for Azure queue storage.

    But in the Node.js we can import the azure dlls.

    But my requirement is to create a queue from pure javascript/jquery.



    • Edited by sk2014 Thursday, May 19, 2016 6:15 AM
    Thursday, May 19, 2016 6:15 AM
  • To call the rest services from the browser, you need to enable CORS.  

    You can learn more about that here:

        https://msdn.microsoft.com/en-us/library/azure/dn535601.aspx

    You can use this powershell command to configure CORS on your storage account:

        https://msdn.microsoft.com/en-us/library/azure/mt619474.aspx

    Once you have CORS configured appropriately, you can call the REST services from Javascript in the browser.  

    It is recommended that you use SAS to authenticate REST calls from browsers, and not distribute your storage account keys.  

    You can learn more about Account SAS here:

        https://msdn.microsoft.com/en-us/library/azure/mt584140.aspx

    The following is a very basic example of creating a queue from JS in a browser:

    <!DOCTYPE html>
    
    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="utf-8" />
        <title></title>
    
    </head>
    <body>
        Account: <input id="account" /><br />
        SAS: <input id="sas" /><br />
        Queue: <input id="queue" /><br />
        <button onclick="createQueue()">Create Queue</button>
        <p id="result"></p>
    
        <script>
    function createQueue() {
        var data = null;
    
        var xhr = new XMLHttpRequest();
        
        xhr.addEventListener("readystatechange", function () {
            if (this.readyState === 4) {
                document.getElementById("result").innerHTML = this.status + " " + this .statusText;
            }
        });
    
        var url = "https://" + document.getElementById("account").value + ".queue.core.windows.net/" + document.getElementById("queue").value + "?" + document.getElementById("sas").value;
    
        xhr.open("PUT", url);
        xhr.setRequestHeader("content-type", "application/xml");
        xhr.setRequestHeader("cache-control", "no-cache");
    
        xhr.send(data);
    
    }
        </script>
    </body>
    </html>




    Wednesday, May 25, 2016 6:41 PM