Random StorageException while sending message to Azure Storage Queue (Not always)

582 views Asked by At

I am getting the following exception randomly when I try to send some message to the Cloud Queue of Azure Storage. I am using version 0.5.1 of the azure storage client library for android. I am not using SAS, instead I am using Azure Account name and key. Please help me solving this issue.

com.microsoft.azure.storage.StorageException: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. at com.microsoft.azure.storage.core.StorageRequest.materializeException(StorageRequest.java:307) at com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:181) at com.microsoft.azure.storage.queue.CloudQueue.exists(CloudQueue.java:887) at com.microsoft.azure.storage.queue.CloudQueue.createIfNotExists(CloudQueue.java:526) at com.microsoft.azure.storage.queue.CloudQueue.createIfNotExists(CloudQueue.java:501)

Edit: Here is my code which caused the exception. As I said it works fine sometimes, the exception happens randomly.

    try
    {
        // Retrieve storage account from connection-string.
        CloudStorageAccount storageAccount =
                CloudStorageAccount.parse(STORAGE_CONNECTION_STRING);

        // Create the queue client.
        CloudQueueClient queueClient = storageAccount.createCloudQueueClient();

        // Retrieve a reference to a queue.
        CloudQueue queue = queueClient.getQueueReference(QUEUE);

        // Create the queue if it doesn't already exist.
        queue.createIfNotExists();

        // Create a message and add it to the queue.
        CloudQueueMessage message = new CloudQueueMessage(msg);
        queue.addMessage(message);
    }
    catch (Exception e)
    {
        // Output the stack trace.
        e.printStackTrace();
    }
1

There are 1 answers