0

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.

MrDeveloper
  • 1,041
  • 12
  • 35
  • 2
    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. – Gaurav Mantri Jun 23 '15 at 09:39
  • Does the job well! If you want to write this as an answer, I'll accept it. – MrDeveloper Jun 25 '15 at 07:30

1 Answers1

1

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);
Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241