今天碰到一个很讨厌的问题,使用nodejs 接收Azure service bus队列消息的时候,出现了:@strin3http//schemas.microsoft.com/2003/10/Serialization/�html
如何产生的:node
使用 C# 往队列中插入消息,使用 nodejs 读取消息。url
出现乱码的缘由:spa
写入消息使用AMQP对象进行序列化,读取的时候使用http进行传输。code
解决办法:orm
写入的时候改用 stream 的方式写入而不是直接写入字符串。htm
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 的个回答:blog