Identifying a message's origin on an ESB

138 Views Asked by At

Using Azure Service Bus, is there a way of recording on a brokered message where that message originated from ? Whilst of being little functional use, I can see it as being a useful tool for DevOps if troubleshooting a problem.

For example, imagine an UpdateCustomer message that could be published from both Billing and CRM applications on the same ESB.

I have thought about prefixing the BrokeredMessage.MessageId with the applications name, but this seems rather hacky. Is there a better way to record the origin of the message ?

Solution

Thanks to Gaurav Mantri for the answer, I've gone and implemented an extension method on the BrokeredMessage object to allow for adding a dictionary of custom properties :

Usage

BrokeredMessage message = new BrokeredMessage();

var customMessageProperties = new CustomMessageProperties()
{
    MessageOrigin = this.PublisherName,
};

message.AddCustomProperties(customMessageProperties.AllCustomProperties);

And the extension method

public static class BrokeredMessageExtensionMethods
{
    public static void AddCustomProperties(this BrokeredMessage brokeredMessage, Dictionary<string, string> properties)
    {
        foreach (var property in properties)
        {
            brokeredMessage.Properties.Add(property.Key, property.Value);
        }
    }
}

Hope this might help someone.

1

There are 1 best solutions below

0
On BEST ANSWER

You could try custom properties on a brokered message which takes a list of name/value pairs: https://msdn.microsoft.com/en-us/library/microsoft.servicebus.messaging.brokeredmessage.properties.aspx.

Something like:

                var queueClient = QueueClient.CreateFromConnectionString(ConnectionString, path);
                var msg = new BrokeredMessage("Message Content");
                msg.Properties.Add("Source", "Message Source");
                await queueClient.SendAsync(msg);