Azure Function App puts ApplicationProperties of ServiceBusMessage into the body instead of its own ApplicationProperties property

1 week ago 4
ARTICLE AD BOX

I have an Azure Function App version 4 using .NET 8. It is an isolated worker function app if that helps.

It is referring these packages:

<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.20.1" /> <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.51.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.ServiceBus" Version="5.24.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues" Version="5.5.3" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.3.1" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.7" />

This is the code of one of the functions I use in there, all of them is pretty much the same with different values set in the ApplicationProperties

[Function("SampleFunction")] [ServiceBusOutput("myschedule", Connection = "ServiceBusConnString")] public ServiceBusMessage SampleFunction([TimerTrigger("0 1 1 1/1 * *")] TimerInfo myTimer) { var result = new ServiceBusMessage(); result.ApplicationProperties.Add("CreatedDate", DateTime.UtcNow); result.ApplicationProperties.Add("DataType", "SampleFunction"); result.ApplicationProperties.Add("UniqueId", Guid.NewGuid()); return result; }

However, when the message is received in the Azure Service Bus, the data I have set is found in the Body of the message instead of the ApplicationProperties of the message.

Message Body

The message properties are empty:

Message Properties

In Visual Studio, you will see them both are different properties of ServiceBusMessage object:

Visual Studio IntelliSense

So I have a few questions in hope of clarifying if I'm insane or there are things I misunderstood from the design of the new Azure.Messaging.ServiceBus library works:

How to set the ApplicationProperties a.k.a Message Properties properly without having it go to the Body? On the receiver side, if I try to read message.ApplicationProperties, I will get the Message Properties instead of the ones in the Body.

Is this by design or was it a mistake from Azure to double enveloped the properties like this? Or actually, was I the one using Azure Function App incorrectly?

I can simply read them from the Body on my receiver side but that's quite cumbersome to handle it that way and the next developer may have to go through the same thinking process to end up nowhere.

Read Entire Article