【问题标题】:Special character in azure storage queue message天蓝色存储队列消息中的特殊字符
【发布时间】:2021-01-08 13:46:37
【问题描述】:

我有这个简单的代码:

  QueueClient azQueue = new QueueClient(@"<connection string>", "test-queue");                
  azQueue.SendMessage("test®test");

它失败并显示消息:“6 次尝试后重试失败。” 如果我从字符串中删除 ® 字符,它会毫无问题地发送消息。 请帮我正确处理特殊字符。

【问题讨论】:

  • 您很可能需要对消息进行编码或从其他地方(如数据库)获取它
  • 最初我是从 db 获取字符串。这就是我发现这个问题的方式。这里只是简化的例子。

标签: c# .net azure-storage azure-queues azure-storage-queues


【解决方案1】:

我相信您使用的是较新的 SDK Azure.Storage.Queues,它不会像以前的 Microsoft.Azure.Storage.QueueWindowsAzure.Storage(已弃用)那样自动在 Base64 中编码消息。所以最好像下面这样对你的信息进行编码。另请参考:https://github.com/Azure/azure-sdk-for-net/issues/11358,还有一个功能请求https://github.com/Azure/azure-sdk-for-net/issues/10242

  QueueClient azQueue = new QueueClient(@"<connection string>", "test-queue");                
  azQueue.SendMessage(Convert.ToBase64String(Encoding.UTF8.GetBytes("test®test")));

【讨论】:

  • 是的,我正在使用最新的 Azure.Storage.Queues 12.4.2。所以我必须将所有消息编码为base64?并且消息的最大大小将被编码为 base64,对吗?奇怪的是,ms docs 中没有提到它。
  • 是的。不幸的是,当前的文档没有明确提到这一点。还有一个功能请求github.com/Azure/azure-sdk-for-net/issues/10242
猜你喜欢
  • 1970-01-01
  • 2013-11-08
  • 2021-01-26
  • 2021-10-21
  • 1970-01-01
  • 2013-11-12
  • 2021-07-17
  • 2012-10-08
  • 1970-01-01
相关资源
最近更新 更多