如何在 ServiceBusMessage 中设置应用程序属性?

How to set application properties in a ServiceBusMessage?

我们如何使用最新的 SDK azure-messaging-servicebus 添加自定义属性或应用程序属性?

在以前的包 com.microsoft.azure:azure-servicebu 中似乎可以使用方法 setProperties(Map properties) 但我找不到新 SDK 的任何内容...

它也可以通过 .Net 或 Javascript SDK 实现。

设置应用程序属性可以通过使用 ServiceBusMessage 上的 ApplicationProperties 地图来完成。例如:

ServiceBusMessage message = new ServiceBusMessage(ServiceBusMessage(BinaryData.fromString("Hello"));
        message.getApplicationProperties().put("EventType", "com.microsoft.samples.hello-event");
        message.getApplicationProperties().put("priority", 1);
        message.getApplicationProperties().put("score", 9.0);

可以在 ServiceBusMessage docs 中找到更多上下文。