开发者

Maximum CloudQueueMessage payload size issue

According to MSDN, the Message payload may extend up to 8KB (8192 bytes):

The AddMessage method adds a message to the back of the queue. A message may be up to 8 KB in size. Its content must be in a format that can be encoded with UTF-开发者_如何学Python8.

However, when adding messages into the Queue I'm receiving exceptions for messages who's payload should be way less that 8192 bytes, the magic region seems to be around 6500 bytes. The data I'm sending are pure strings, who's size is validated both from the .Length member and a length sent by the source where they are retrieved from (there is a constant 2 byte difference for a CRLF delimiter).

so my question is two-fold:

1) Is there any hidden data appended to the message payload that would balloon its size or cause this odd kind of behavior? (such as the limit being applied to the object as a whole and not just its payload, but even then, how can it account for 1.5KB per message?)

2) How can I reliably check that the payload is is indeed below 8192?

and some extra info: I'm using the Azure SDK 1.4 with VS 2010 Ultimate, running through the compute & storage emulators (I haven't deployed this app yet) using SQLExpress (2008 I think).

Also confirmed via code that the max size is 8192 bytes (in case of some extra system imposed limit):

Trace.WriteLine("Max Queue Message Size: " + CloudQueueMessage.MaxMessageSize, "CloudQueueMessage");

CloudQueueMessage: Max Queue Message Size: 8192


The .NET storage client library (Microsoft.WindowsAzure.StorageClient.dll) base-64-encodes queue message content, so the effective limit is 8192 * .75 = 6144 bytes when you use the .NET client library. (That's because base 64 encoding adds a 1/3rd overhead.)

(Note that you don't have to base 64 encode. It just happens to be the way this library ensures that the content of the queue message can be safely embedded in XML, which is the requirement the queue service places on messages.)


EDIT: Here's sample code for using the Microsoft.WindowsAzure.StorageClient.Protocol namespace to put raw text (not base 64 encoded) in a queue message (and subsequently retrieve it):

using System;
using System.Net;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;
using Microsoft.WindowsAzure.StorageClient.Protocol;

class Program
{
    static void Main(string[] args)
    {
        var q = CloudStorageAccount.Parse("UseDevelopmentStorage=true").CreateCloudQueueClient().GetQueueReference("testqueue");
        q.CreateIfNotExist();

        var req = QueueRequest.PutMessage(new Uri(q.Uri, q.Name + "/messages"), 30, null);
        var body = QueueRequest.GenerateMessageRequestBody("hello world");
        req.ContentLength = body.Length;
        q.ServiceClient.Credentials.SignRequest(req);
        using (var stream = req.GetRequestStream())
        {
            stream.Write(body, 0, body.Length);
            stream.Close();
        }
        req.GetResponse();

        req = QueueRequest.GetMessages(new Uri(q.Uri, q.Name + "/messages"), 30, 32, null);
        q.ServiceClient.Credentials.SignRequest(req);
        using (var response = (HttpWebResponse)req.GetResponse())
        {
            using (var msgResponse = QueueResponse.GetMessages(response))
            {
                foreach (var msg in msgResponse.Messages)
                {
                    Console.WriteLine("MESSAGE: " + msg.Text);
                    q.DeleteMessage(msg.Id, msg.PopReceipt);
                }
            }
        }

        q.Delete();
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜