我正在使用 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
为 null 或messageHeaders[message]
存在但包含 null 值时才会发生。不幸的是,我还无法弄清楚其中哪种情况更有可能(甚至可能)
更新 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();
(我已经修剪了所有的命名空间)