Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a custom property using the Azure.Messaging.ServiceBus library?

the latest sdk (Azure.Messaging.ServiceBus 7.0.1) doesn't seem to have the option to add custom(user) properties to a message (ie: for filtering topic subs). Has anyone found out how to do this now? SendMessageAsync

like image 265
sharpc Avatar asked Jan 24 '21 21:01

sharpc


2 Answers

It was replaced by ServiceBusMessage.ApplicationProperties:

In v7, the userProperties and label on the message were renamed to applicationProperties and subject to be in sync with the AMQP spec. We did this across languages as part of our new SDKs.

We realize that we should have done a better job at communicating this in our migration guide which is linked from the readme for the package in npm and github as well as from our changelog. We will do so immediately.

https://github.com/Azure/azure-sdk-for-js/issues/12861#issuecomment-743406738

like image 53
David Browne - Microsoft Avatar answered Oct 24 '22 13:10

David Browne - Microsoft


Adding on to @David's answer. This property is read-only hence you can't simply write:

message.ApplicationProperties = new Dictionary<string, object>();

In order to add your custom properties in this dictionary use:

ServiceBusMessage message = new ServiceBusMessage(content);
message.ApplicationProperties.Add("yourKey", "yourValue");

Please refer to this official GitHub documentation for further details around topic filtering.

like image 11
AshutoshTripathi Avatar answered Oct 24 '22 13:10

AshutoshTripathi