【发布时间】:2013-08-27 00:13:20
【问题描述】:
当传出标头是静态的时,NServiceBus 如何保持一致性?
这是否意味着如果我为特定消息设置传出标头,它会影响所有其他传出消息,因为它是单例?
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;
.
.
.
}
然而,传入的标头似乎被正确标记为[ThreadStatic]。
解释一下。
=========================编辑====================== ========
我想我正在尝试理解,因为许多示例都显示了以下代码:
Bus.OutgoingHeaders["Test"] = g.ToString("N");
追溯至:
IDictionary<string, string> IBus.OutgoingHeaders
{
get
{
return ExtensionMethods.GetStaticOutgoingHeadersAction();
}
}
设置在:
内部类引导程序:INeedInitialization、IWantToRunWhenConfigurationIsComplete { 公共 MessageHeaderManager 管理器 { 获取;放; }
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());
}
}
当然,上面最后一行中的 GetStaticOutgoingHeaders 转到静态字段。
我正在尝试弄清楚如何为 下一个 消息设置标题。但是,如果我按照示例进行操作,我最终会为所有消息设置标题。
【问题讨论】:
标签: c# message-queue nservicebus soa