发送带有新库(Microsoft.Azure.ServiceBus)的消息,该消息由具有BodyType-字符串的旧库(Microsoft.ServiceBus.Messaging)读取 [英] Send a message with a new library (Microsoft.Azure.ServiceBus) that is read by an old library (Microsoft.ServiceBus.Messaging) with BodyType - String

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

问题描述

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

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. 互操作扩展名执行相反操作(在新客户端中读取旧消息)

  1. A stackoverflow answer
  2. Interop extension to do the opposite (read an old message in the new client)


推荐答案

该方案在此处
您将需要按照以下方法来序列化消息:

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(); 
 }

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

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