问题
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:
- A stackoverflow answer
- 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