How is NServiceBus maintaining consistency when the outgoing headers is static?
Does it mean if I were to set the outgoing headers for a particular message, it will affect all other outgoing messages since it's a 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 to be correctly marked as [ThreadStatic]
however.
Explain.
========================EDIT==============================
I guess I'm trying to understand because many examples show the code below:
Bus.OutgoingHeaders["Test"] = g.ToString("N");
Which's traced to:
IDictionary<string, string> IBus.OutgoingHeaders
{
get
{
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 the GetStaticOutgoingHeaders in the last line above goes to a static field.
I'm trying to figure out how to set the header, for the next message. But if I follow the examples, I end up setting the headers for ALL messages.