Question

I'm attempting to follow Best Practices for Handling Large Messages with Windows Azure Queues and I've fallen at the first hurdle. The article advises compressing a message before adding it to an Azure Queue, which I've tried to do using the following code...

$compressedMessage = gzcompress('Test', 9);
try {
  $queueRestProxy->createMessage($queueName, $compressedMessage);  
} catch (ServiceException $e) {
  $code = $e->getCode();
  $error_message = $e->getMessage();
  echo $code . ': ' . $error_message . '<br />';
}

Unfortunately, a ServiceException is raised as follows...

400: Fail: Code: 400 Value: XML specified is not syntactically valid. details (if any): InvalidXmlDocumentXML specified is not syntactically valid. RequestId:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX Time:2014-02-07T20:04:07.8227706Z316Error parsing Xml content.

Removing the call to gzcompress (i.e. passing the string without compression) results in the message 'Test' being successfully added to the queue.

Does anyone know how I can overcome this issue?

Was it helpful?

Solution

I believe the reason you're getting this error is because when you are compressing the string, you're getting a string like x┌♂I-.☺ ♥▌☺íe. As you can see it has some weird looking characters. One thing you could do is convert that string into base64 encoded format and then save that as message.

$compressedMessage = gzcompress('Test', 9);

$queueRestProxy->createMessage("test", base64_encode($compressedMessage));

I just tried the same and it saved the message properly. One thing you would need to keep in mind is that when you get the message, you have to decode it first before decompressing it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top