【问题标题】:Error 400 response after calling createMessage with compressed string (Azure Queue REST Proxy)使用压缩字符串调用 createMessage 后出现错误 400 响应(Azure Queue REST 代理)
【发布时间】:2014-03-05 09:47:02
【问题描述】:

我正在尝试关注Best Practices for Handling Large Messages with Windows Azure Queues,但我在第一个障碍中跌倒了。该文章建议在将消息添加到 Azure 队列之前对其进行压缩,我尝试使用以下代码进行此操作...

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

不幸的是,ServiceException 如下引发...

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.

删除对gzcompress 的调用(即不压缩传递字符串)会导致消息“Test”成功添加到队列中。

有谁知道我该如何解决这个问题?

【问题讨论】:

    标签: php azure compression azure-storage azure-storage-queues


    【解决方案1】:

    我相信您收到此错误的原因是因为当您压缩字符串时,您会得到一个类似 x┌♂I-.☺ ♥▌☺íe 的字符串。正如你所看到的,它有一些看起来很奇怪的字符。您可以做的一件事是将该字符串转换为 base64 编码格式,然后将其保存为消息。

    $compressedMessage = gzcompress('Test', 9);
    
    $queueRestProxy->createMessage("test", base64_encode($compressedMessage));
    

    我只是尝试了同样的方法,它正确保存了消息。您需要记住的一件事是,当您收到消息时,您必须先对其进行解码,然后再对其进行解压缩。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-20
      • 2011-11-12
      • 1970-01-01
      • 1970-01-01
      • 2020-10-05
      • 2017-03-24
      相关资源
      最近更新 更多