I am trying to use Azure function output bindings to send message to a service bus topic having one subscription
Following piece of code is doing the job but I am not able to set
- Custom Properties
- Message Properties ( contentType, messageId etc )
[Function(nameof(Function1))]
[ServiceBusOutput("test-topic", Connection = "CONN")]
public async Task<OutputData> Run(
[ServiceBusTrigger("test-queue", Connection = "CONN")]
ServiceBusReceivedMessage message,
ServiceBusMessageActions messageActions,
ICollector<BrokeredMessage> collector
)
{
//Following return
//Is there any way to set custom properties of this message?
//Along with custom property, I would also like to set messageProperty contentType to application/json
OutputData outputData = new OutputData
{
ID = 123,
Name = "Test"
};
// Complete the message
await messageActions.CompleteMessageAsync(message);
return outputData;
/*As per solution mentioned [here](https://stackoverflow.com/questions/50457428/custom-message-properties-on-azure-queue-topic-message-from-azure-function), I tried to set custom properties but collector is always null.*/
BrokeredMessage brokeredMessage = new();
brokeredMessage.ContentType = "application/json";
brokeredMessage.Properties.Add("ID", 123);
brokeredMessage.Properties.Add("Name", "Test");
//Injecting ICollector<BrokeredMessage> notworking as its always null.
//collector.Add(brokeredMessage);
}
I can see outputData has reached to its destination but content type is text/plain and I can't add any custom properties.

I am using
- .NET 9 ( Git repo)
- Azure service bus ( standard )
Any pointers ?
UPDATE 1
As suggested by @Dasari Kamali I tried using ServiceBusMessage but still observing same behavior
#region ServiceBusMessage not working
ServiceBusMessage serviceBusMessage = new ServiceBusMessage();
serviceBusMessage.ContentType = "application/json";
serviceBusMessage.ApplicationProperties.Add("ID", 123);
serviceBusMessage.ApplicationProperties.Add("Name", "Test");
serviceBusMessage.Body = BinaryData.FromString("Test");
#endregion
// Complete the message
await messageActions.CompleteMessageAsync(message);
return serviceBusMessage;




ServiceBusMessageinstead ofBrokeredMessageto set custom properties andContentTypein the output binding.ServiceBusMessageis also not helpful. Am I missing anything else?ServiceBusSenderfrom aServiceBusClientand explicitly sends the message usingSendMessageAsync(). This approach successfully worked for me to set theContentTypeasapplication/jsonunder the Message Properties in the Topic.