How to set application properties in a ServiceBusMessage?

Viewed 440

How can we add custom properties or application properties with the latest SDK azure-messaging-servicebus?

It seems something doable in the previous package com.microsoft.azure:azure-servicebu like the method setProperties(Map<String,Object> properties) but I cannot find anything with the new SDK...

It is also something doable with the .Net or Javascript SDK .

1 Answers

Setting application properties can be accomplished by using the ApplicationProperties map on ServiceBusMessage. For example:

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);

More context can be found in the ServiceBusMessage docs.

Related