我正在使用NServiceBus 3,当我收到消息时,我从接收端点收到此错误。:
NServiceBus.Unicast.Transport.Transactional.TransactionalTransport [(null)] <(null)> - Failed raising 'transport message received' event for message with ID=97d0f2fa-6227-439b-ad37-a304bd2af000\10428
System.NullReferenceException: Object reference not set to an instance of an object.
at NServiceBus.MessageHeaders.MessageHeaderManager.GetHeader(Object message, String key)
at NServiceBus.MessageHeaders.Bootstrapper.<Run>b__0(Object msg, String key)
at NServiceBus.ExtensionMethods.GetHeader(Object msg, String key)
at NServiceBus.ExtensionMethods.GetOriginatingSiteHeader(Object msg)
at NServiceBus.Gateway.HeaderManagement.GatewayHeaderManager.MutateIncoming(Object message)
at NServiceBus.Unicast.UnicastBus.<>c__DisplayClass25.<ApplyIncomingMessageMutatorsTo>b__24(IMutateIncomingMessages m)
at System.Collections.Generic.List`1.ForEach(Action`1 action)
at NServiceBus.Unicast.UnicastBus.ApplyIncomingMessageMutatorsTo(IBuilder builder, Object originalMessage)
at NServiceBus.Unicast.UnicastBus.<>c__DisplayClass22.<HandleMessage>b__21(Object msg)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at NServiceBus.Unicast.UnicastBus.HandleMessage(IBuilder builder, TransportMessage m)
at NServiceBus.Unicast.UnicastBus.HandleTransportMessage(IBuilder childBuilder, TransportMessage msg)
at NServiceBus.Unicast.UnicastBus.TransportMessageReceived(Object sender, TransportMessageReceivedEventArgs e)
at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
at NServiceBus.Unicast.Transport.Transactional.TransactionalTransport.OnTransportMessageReceived(TransportMessage msg)
消息本身如下:
public interface ILinkPersonMessage : IBaseMessage
{
int PersonId { get; set; }
List<int> UnitIds { get; set; }
}
public interface IBaseMessage
{
int UserId { get; set; }
}
在发送课程中,我这样做:
var message = bus.CreateInstance<ILinkPersonMessage>();
message.UserId = currentUser.UserId;
message.PersonId = personId;
message.UnitIds = selectedUnits;
bus.Send(message);
更新
我正在查看NServiceBus代码,这是抛出错误的方法:
public string GetHeader(object message, string key)
{
if (message == ExtensionMethods.CurrentMessageBeingHandled)
if (bus.CurrentMessageContext.Headers.ContainsKey(key))
return bus.CurrentMessageContext.Headers[key];
else
return null;
if (messageHeaders == null)
return null;
if (!messageHeaders.ContainsKey(message))
return null;
if (messageHeaders[message].ContainsKey(key))
return messageHeaders[message][key];
return null;
}
通过查看该代码,只有在bus.CurrentMessageContext
或bus.CurrentMessageContext.Headers
为空,或者messageHeaders[message]
存在但包含空值时才会发生这种情况。不幸的是,我还没有弄清楚这些场景中哪一个更有可能(甚至可能)
更新2
所以使用QueueExplorer我已经把标题拉出来了:
<?xml version="1.0"?>
<ArrayOfHeaderInfo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<HeaderInfo>
<Key>NServiceBus.Version</Key>
<Value>3.0.3</Value>
</HeaderInfo>
<HeaderInfo>
<Key>NServiceBus.TimeSent</Key>
<Value>2012-05-08 06:57:15:691208 Z</Value>
</HeaderInfo>
<HeaderInfo>
<Key>NServiceBus.EnclosedMessageTypes</Key>
<Value>Namespace.Service.ILinkPersonMessage __impl, NServiceBus.Unicast.Transport__impl, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null;Namespace.Service.ILinkPersonMessage, Namespace.Service, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</Value>
</HeaderInfo>
<HeaderInfo>
<Key>WinIdName</Key>
<Value>*{myusername}*</Value>
</HeaderInfo>
<HeaderInfo>
<Key>CorrId</Key>
</HeaderInfo>
</ArrayOfHeaderInfo>
更新3
这是现在有效的流畅配置:
Configure.With()
.DefiningEventsAs(t => t.Namespace != null && t.Namespace.StartsWith("Events"))
.DefiningCommandsAs(t => t.Namespace != null && t.Namespace.StartsWith("Messages"))
.CastleWindsorBuilder(container)
.XmlSerializer()
.MsmqTransport()
.IsTransactional(true)
.IsolationLevel(IsolationLevel.ReadUncommitted)
.UnicastBus()
.RavenSagaPersister()
.RavenSubscriptionStorage()
.UseRavenTimeoutPersister()
.RunTimeoutManager()
.ForInstallationOn<NServiceBus.Installation.Environments.Windows>().Install();
(我已经修剪了所有命名空间)
答案 0 :(得分:2)
这是在发送进程启动后的第一条消息上发生的,还是只发生在后续消息上?
您是否多次配置发送总线? (NServiceBus.Configure?)
答案 1 :(得分:1)
我们最近修复了标头管理方面的一些错误,因此可能就是您遇到的问题。请尝试升级到3.0.4并查看是否能解决您的问题。
答案 2 :(得分:1)
同样的事情发生在我身上,问题是我在配置服务总线时忘了设置xmlserialization
var configBus = NServiceBus.Configure.With()
.DefaultBuilder()
.MsmqSubscriptionStorage()
.XmlSerializer() // <== This line here
.MsmqTransport()
.IsTransactional(true)
.PurgeOnStartup(false)
.UnicastBus()
.ImpersonateSender(true);