2015-06-23 40 views
0

使用Azure服務總線,是否有在代理消息中記錄消息來源的方式?雖然在功能上很少使用,但在解決問題時,我可以將其視爲DevOps的有用工具。在ESB上標識消息的來源

例如,想象一下可在同一ESB上從Billing和CRM應用程序發佈的UpdateCustomer消息。

我曾想過在應用程序名稱前加上BrokeredMessage.MessageId,但這看起來相當不合理。有沒有更好的方法來記錄消息的來源?

解決方案

感謝拉夫Mantri的答案,我已經實施了BrokeredMessage對象上的擴展方法,允許添加自定義屬性的字典:

使用

BrokeredMessage message = new BrokeredMessage(); 

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

message.AddCustomProperties(customMessageProperties.AllCustomProperties); 

而且擴展方法

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

希望這可能有助於某人。

+2

你可以嘗試在通知代理消息這需要名稱/值對的列表,自定義屬性:https://msdn.microsoft.com/en-us/library/microsoft。 servicebus.messaging.brokeredmessage.properties.aspx。 –

+0

做得好!如果你想寫這個答案,我會接受它。 – MrDeveloper

回答