'MassTransit publishing custom properties for Azure Service Bus

Does anyone know how I can publish ApplicationProperties (aka custom properties) to Azure Service Bus via the MassTransit Publish?

In the native ASB client library, we can do this...

var message = new ServiceBusMessage(msg);
message.ApplicationProperties.Add("foo", "bar");

But I can't see how to do that in MassTransit. Looking at the overloads for the Publish method, the closest thing I can see is the headers - ie...

await _bus.Publish(new SomeEvent { SomeProperty = "some-value" },
    context =>
    {
        context.Headers.Set("MyCustomProperty", "my-custom-value");
    },
cancellationToken);

UPDATE: I wrote the above snippet, as an example of what I'm doing - but it wasn't an exact copy. It turns out after seeing Chris's answer - that the above snippet does work - but in my actual code, "some-value" was actually a boolean - which is what the issue was!

But that just adds headers to the MT message envelope - not ASB custom properties.

Ie. in my first example, this is where I see the field in Azure Service Bus explorer...

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source