Search code examples
azureservicebusazure-scheduler

Azure Scheduler and Azure Service Bus


I'm using Azure Scheduler to place a message in a topic in Azure Service Bus. In Azure Scheduler I have entered the following information in the "Message" property:

{"StartTid":null,"Id":"c594eab8-382c-49ec-ba9c-2db0aaf5e167","CreationDate":"2018-02-11T17:42:42.9823622Z","TenantId":null}

When retrieving the message from my app, using this code:

var messageData = Encoding.UTF8.GetString(message.Body);

The message I get looks like this:

@string3http://schemas.microsoft.com/2003/10/Serialization/�{{"StartTid":null,"Id":"c594eab8-382c-49ec-ba9c-2db0aaf5e167","CreationDate":"2018-02-11T17:42:42.9823622Z","TenantId":null}

It seems like Azure Scheduler is adding information to the message.

What is the correct way to retrieve only the message I entered in Azure Schedulers Message property without get all the garbage?


Solution

  • Azure Service Bus .NET Standard Client deals with streams only. When the old client is used and data is not sent using a stream, the receiving code based on Azure Service Bus .NET Standard Client has to perform de-serialization as was outlined in the other answer. There's a Broken Wire Compatability issue that was closed by the messaging team that has the details.

    The good news is that you don't need the serializer code in your code base. The new client has an interop extension method for Message so you don't have to deal with data contract deserialization. For example, in your case you'd be able to write

    var message = await messageReceiver.ReceiveAsync();
    var data = message.GetBody<string>();