Azure ServiceBus Message Serialization/Deserialization

前端 未结 3 652
太阳男子
太阳男子 2020-12-15 10:25

I am using a .NET Core application to send an object through an Azure Service Bus Queue and have it received by a Web Job (.NET Core as well.)

My question is how to

3条回答
  •  自闭症患者
    2020-12-15 11:02

    how to serialize/deserialize to send/receive the object?

    Please refer to the demo code blow:

    Send message:

    var body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(obj));
    await  queueClient.SendAsync(new Message { Body = body, ContentType = "text/plain" });
    

    In the .net core WebJob

    var body = Encoding.UTF8.GetString(message.Body);
    var obj = JsonConvert.DeserializeObject(body);
    

    Test Result:

提交回复
热议问题