在我的域中发布一个事件后,我一直从我的非规范化主机收到以下消息:
2011-07-22 14:18:32,374 [Worker.5] WARN NServiceBus.Unicast.UnicastBus [(null)]
<(null)> - Received an empty message - ignoring.
我只是这样做与jolivereventstore:
return Wireup.Init()
.UsingRavenPersistence("EventStore", new DocumentObjectSerializer())
.UsingAsynchronousDispatcher()
.PublishTo(new DelegateMessagePublisher(c => container.Resolve<IPublishMessages>().Publish(c)))
.Build();
IPublishMessages解析为:
public sealed class NServiceBusPublisher : IPublishMessages
{
private const string AggregateIdKey = "AggregateId";
private const string CommitVersionKey = "CommitVersion";
private const string EventVersionKey = "EventVersion";
private const string BusPrefixKey = "Bus.";
private readonly IBus bus;
public NServiceBusPublisher(IBus bus)
{
this.bus = bus;
}
public void Dispose()
{
GC.SuppressFinalize(this);
}
public void Publish(Commit commit)
{
for (var i = 0; i < commit.Events.Count; i++)
{
var eventMessage = commit.Events[i];
var busMessage = eventMessage.Body as IMessage;
AppendHeaders(busMessage, commit.Headers); // optional
AppendHeaders(busMessage, eventMessage.Headers); // optional
AppendVersion(commit, i); // optional
this.bus.Publish(busMessage);
}
}
private static void AppendHeaders(IMessage message, IEnumerable<KeyValuePair<string, object>> headers)
{
headers = headers.Where(x => x.Key.StartsWith(BusPrefixKey));
foreach (var header in headers)
{
var key = header.Key.Substring(BusPrefixKey.Length);
var value = (header.Value ?? string.Empty).ToString();
message.SetHeader(key, value);
}
}
private static void AppendVersion(Commit commit, int index)
{
var busMessage = commit.Events[index].Body as IMessage;
busMessage.SetHeader(AggregateIdKey, commit.StreamId.ToString());
busMessage.SetHeader(CommitVersionKey, commit.StreamRevision.ToString());
busMessage.SetHeader(EventVersionKey, GetSpecificEventVersion(commit, index).ToString());
}
private static int GetSpecificEventVersion(Commit commit, int index)
{
// e.g. (StreamRevision: 120) - (5 events) + 1 + (index @ 4: the last index) = event version: 120
return commit.StreamRevision - commit.Events.Count + 1 + index;
}
}
发布事件的NServiceBus主机有以下配置:
<MsmqTransportConfig
InputQueue="SonatribeInputQueue"
ErrorQueue="error"
NumberOfWorkerThreads="1"
MaxRetries="5"
/>
<UnicastBusConfig
DistributorControlAddress=""
DistributorDataAddress=""
ForwardReceivedMessagesTo="">
<MessageEndpointMappings>
<add Messages="Events" Endpoint="SonatribeInputQueue"/>
</MessageEndpointMappings>
</UnicastBusConfig>
接收事件的反规格化主机为:
<MsmqTransportConfig
InputQueue="MyServerInputQueue"
ErrorQueue="error"
NumberOfWorkerThreads="1"
MaxRetries="5"
/>
<UnicastBusConfig>
<MessageEndpointMappings>
<add Messages="Events" Endpoint="SonatribeInputQueue"/>
</MessageEndpointMappings>
</UnicastBusConfig>
这对我来说似乎是正确的-发布者处理从web发送的命令,域引发事件。NServiceBusPublisher发布事件,而反规格化主机至少会收到一些东西!它只是不是它被发送的消息-或者发生了一些事情至少让它认为消息是空的....
有人知道吗?
* * * * * 更新 * * * * * * * * * * *
我现在从l4n得到以下内容:
2011-07-22 16:31:30,646 [Worker.7] ERROR NServiceBus.Faults.InMemory.FaultManage
r [(null)] <(null)> - Serialization failed for message with ID 56b7b693-090f-49b
d-83ad-7beeb334fe6d12639.
System.Security.VerificationException: Operation could destabilize the runtime.
at SetId(Object , Object )
at NServiceBus.Serializers.XML.MessageSerializer.GetObjectOfTypeFromNode(Type
t, XmlNode node) in c:DevNServiceBussrcimplSerializersNServiceBus.Seriali
zers.XMLMessageSerializer.cs:line 343
at NServiceBus.Serializers.XML.MessageSerializer.Process(XmlNode node, Object
parent) in c:DevNServiceBussrcimplSerializersNServiceBus.Serializers.XML
MessageSerializer.cs:line 330
at NServiceBus.Serializers.XML.MessageSerializer.Deserialize(Stream stream) i
n c:DevNServiceBussrcimplSerializersNServiceBus.Serializers.XMLMessageSer
ializer.cs:line 267
at NServiceBus.Unicast.UnicastBus.Extract(TransportMessage m) in c:DevNServ
iceBussrcunicastNServiceBus.UnicastUnicastBus.cs:line 851
2011-07-22 16:31:30,908 [Worker.7] WARN NServiceBus.Unicast.UnicastBus [(null)]
<(null)> - Received an empty message - ignoring.
这是它试图反序列化的消息!!
[Serializable]
public class AccountCreatedEvent : IEvent
{
public readonly string Id;
public readonly string Name;
public AccountCreatedEvent()
{
}
public AccountCreatedEvent(string id, string name)
{
this.Id = id;
this.Name = name;
}
public override string ToString()
{
return "AccountCreatedEvent - for when you've created an account";
}
}
很明显,为什么该消息不能被反序列化-您有只读属性。如果你想让这个工作,你需要切换到公共get/set属性。为了保持不公开更改属性的意图,这里有一种替代方法:
[Serializable]
public class AccountCreatedEvent : IEvent
{
public string Id { get; private set; }
public string Name {get; private set; }
public AccountCreatedEvent(string id, string name)
{
this.Id = id;
this.Name = name;
}
public override string ToString()
{
return "AccountCreatedEvent - for when you've created an account";
}
}