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 的个回答:

http://stackoverflow.com/questions/36307767/how-to-remove-strin3http-schemas-microsoft-com-2003-10-serialization-receive

http://stackoverflow.com/questions/33542509/interoperability-azure-service-bus-message-queue-messages

 

posted @ 2017-02-18 23:38  easeyeah  阅读(413)  评论(0编辑  收藏  举报