Send a message with a new library (Microsoft.Azure.ServiceBus) that is read by an old library (Microsoft.ServiceBus.Messaging) with BodyType - String

本秂侑毒 提交于 2019-12-29 01:48:10

问题


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.

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.

Related links:

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

回答1:


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


来源:https://stackoverflow.com/questions/56037363/send-a-message-with-a-new-library-microsoft-azure-servicebus-that-is-read-by-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!