c# - Why NServiceBus OutgoingHeaders is static and not ThreadStatic? -


how nservicebus maintaining consistency when outgoing headers static?

does mean if set outgoing headers particular message, affect other outgoing messages since it's singleton?

namespace nservicebus.messageheaders {   [comvisible(false)]   public class messageheadermanager : imutateoutgoingtransportmessages   {     private static idictionary<string, string> staticoutgoingheaders = (idictionary<string, string>) new dictionary<string, string>();     private iunicastbus bus;     [threadstatic]     private static idictionary<object, idictionary<string, string>> messageheaders;    .    .    .  } 

the incoming header seems correctly marked [threadstatic] however.

explain.

========================edit==============================

i guess i'm trying understand because many examples show code below:

bus.outgoingheaders["test"] = g.tostring("n"); 

which's traced to:

idictionary<string, string> ibus.outgoingheaders {     {     return extensionmethods.getstaticoutgoingheadersaction();   } } 

which's set at:

internal class bootstrapper : ineedinitialization, iwanttorunwhenconfigurationiscomplete { public messageheadermanager manager { get; set; }

void ineedinitialization.init() {   configure.instance.configurer.configurecomponent<messageheadermanager>(dependencylifecycle.singleinstance); }  public void run() {   extensionmethods.getheaderaction = (func<object, string, string>) ((msg, key) => this.manager.getheader(msg, key));   extensionmethods.setheaderaction = (action<object, string, string>) ((msg, key, val) => this.manager.setheader(msg, key, val));   extensionmethods.getstaticoutgoingheadersaction = (func<idictionary<string, string>>) (() => this.manager.getstaticoutgoingheaders()); } 

}

and of course getstaticoutgoingheaders in last line above goes static field.

i'm trying figure out how set header, next message. if follow examples, end setting headers messages.

[update udi] if want set header on specific message you're sending, call .setheader(key, value); method on message object. static outgoing headers useful process-wide data logged-in user in desktop application.[end update]

messageheadermanager imutateoutgoingtransportmessages means concerned messages on way out. there no incoming message headers on display here.

messageheaders concerned headers set per-message, time sent, or set manually message handler.

staticoutgoingheaders place cache headers same every single message out of endpoint values don't need recalculated. include things source machine name.

if guts of mutateoutgoing method, see of key/value pairs both messageheaders , staticoutgoingheaders added transportmessage.headers collection. additionally, static ones added headers.add(key, value) while thread-static headers added via headers[key] = value item thread-static collection override static header of same name.

here's link full source class on github, linked tag v4.0.3 (current @ time of writing) link won't expire.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -