【问题标题】:Azure Service Bus Queue sending a message in NodeJs to .NET clientAzure 服务总线队列在 NodeJs 中向 .NET 客户端发送消息
【发布时间】:2016-02-25 21:48:29
【问题描述】:

我正在从 C# 工作者向队列发送消息,然后我在另一个 C# 工作者上获取它并调用

string body = message.GetBody<string>();

这可行,我稍后会反序列化字符串/JSON 消息。

现在我正在尝试以 JSON 消息的形式从 NodeJS 发送相同的消息。当我尝试接收它并

string body = message.GetBody<string>();

调用这个我得到一个异常,说输入格式不正确。

我在 NodeJS 上的消息对象是这样的

{
  body: JSON.stringify(message)
}

有什么想法吗?

【问题讨论】:

    标签: c# node.js azure azureservicebus azure-servicebus-queues


    【解决方案1】:

    解决了!

    默认情况下,.NET Azure Queue 库在使用时使用 DataContractSerializer 和二进制 XmlDictionaryWriter 来序列化字符串消息

    new BrokeredMessage("my message");

    所以你需要使用这个

    new BrokeredMessage(new MemoryStream(Encoding.UTF8.GetBytes("my message")), true);

    要阅读 C# 中的消息,您需要使用

    string body = new StreamReader(message.GetBody<Stream>(), Encoding.UTF8).ReadToEnd();

    我还停止将我的JSON.stringify 消息包装在一个对象中,并将其直接传递给sendQueueMessage。发送消息代码现在如下所示:

    serviceBusService.sendQueueMessage('my_queue', JSON.stringify("my message"), function(error){});

    JSON.stringify 输出一个 UTF8 字符串,因此它与 C# 代码完全兼容。

    【讨论】:

      猜你喜欢
      • 2018-12-07
      • 2019-09-18
      • 2012-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-19
      相关资源
      最近更新 更多