使用 BodyType - String 由旧库 (Microsoft.ServiceBus.Messaging) 读取的新库 (Microsoft.Azure.ServiceBus) 发送消息 [英] Send a message with a new library (Microsoft.Azure.ServiceBus) that is read by an old library (Microsoft.ServiceBus.Messaging) with BodyType - String

查看:34
本文介绍了使用 BodyType - String 由旧库 (Microsoft.ServiceBus.Messaging) 读取的新库 (Microsoft.Azure.ServiceBus) 发送消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个前段时间写的客户端,它使用旧库,并在接收消息时调用 GetBody() 来读取正文.

I have a client written for some time ago that uses the old library and does call GetBody<string>() to read the body when receiving messages.

现在我有了新客户端 Microsoft.Azure.ServiceBus(发送消息),据我所知,它总是使用 Stream.

Now I have the new client Microsoft.Azure.ServiceBus (sends messages) that as far as I understand always uses Stream.

所以旧客户端只是因为它期望字符串主体类型而崩溃.我找到了很多关于相反场景(新读者,旧作者)的信息,但无法弄清楚如何让新客户端以所需格式发送数据.

So the old client just crashes as it expects string body type. I have found a lot of information on the opposite scenario (new reader, old writer), but cannot figure out how to make the new client send the data in required format.

相关链接:

  1. stackoverflow 答案
  2. 互操作扩展做相反的事情(在新客户端中阅读旧消息)

推荐答案

场景描述 此处.您需要按照以下方法序列化消息:

The scenario is described here. You will need to serialize the message following this approach:

 var serializer = DataContractBinarySerializer<string>.Instance; 
 using (MemoryStream stream = new MemoryStream()) 
 {
     serializer.WriteObject(stream, some_string);
     var msg = new Message(stream.ToArray());
     var client = new Microsoft.Azure.ServiceBus.QueueClient(ConnectionString, Queue);
     await client.SendAsync(msg);
     await client.CloseAsync(); 
 }

这篇关于使用 BodyType - String 由旧库 (Microsoft.ServiceBus.Messaging) 读取的新库 (Microsoft.Azure.ServiceBus) 发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆