Azure ServiceBus的消息中带有@strin3http//schemas.microsoft.com/2003/10/Serialization/?
Posted easeyeah
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Azure ServiceBus的消息中带有@strin3http//schemas.microsoft.com/2003/10/Serialization/?相关的知识,希望对你有一定的参考价值。
今天碰到一个很讨厌的问题,使用nodejs 接收Azure service bus队列消息的时候,出现了:@strin3http//schemas.microsoft.com/2003/10/Serialization/�
如何产生的:
使用 C# 往队列中插入消息,使用 nodejs 读取消息。
出现乱码的原因:
写入消息使用AMQP对象进行序列化,读取的时候使用http进行传输。
解决办法:
写入的时候改用 stream 的方式写入而不是直接写入字符串。
var obj = new { key = i, url = string.Format("http://item.m.jd.com/product/{0}.html", i) };
var bytes = Encoding.ASCII.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(obj)); var stream = new MemoryStream(bytes);
//加入消息 messages.Add(new BrokeredMessage(stream));
Nodejs 接收部分:
//接收队列消息。 var serviceBusService = azure.createServiceBusService("..."); serviceBusService.receiveQueueMessage(\'1001\', function (error, m) { console.log(m); }
stackoverflow 的个回答:
以上是关于Azure ServiceBus的消息中带有@strin3http//schemas.microsoft.com/2003/10/Serialization/?的主要内容,如果未能解决你的问题,请参考以下文章
使用 Windows.Azure.ServiceBus (5.2.0) 的 ServiceBus 消息处理程序无法使用 DataContractSerializer NET 4.6.1 反序列化正文流
Azure 逻辑应用向 ServiceBus 发送 JSON 消息
Azure Messaging-ServiceBus Messaging消息队列技术系列7-消息事务
Azure Messaging-ServiceBus Messaging消息队列技术系列7-消息事务