如何使用 Azure.Messaging.ServiceBus 库添加自定义 属性?

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

最新的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

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

添加到@David 的回答中。 这个 属性 是只读的,因此 你不能简单地写:

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

要在此字典中添加您的自定义属性,请使用:

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

有关主题过滤的更多详细信息,请参阅 this 官方 GitHub 文档。