什么导致EventStore如此容易地抛出ConcurrencyException?

Mat*_*int 3 nservicebus cqrs event-store

使用JOliver EventStore 3.0,开始使用简单的样本.

我有一个使用NServiceBus的简单pub/sub CQRS实现.客户端在总线上发送命令,域服务器接收并处理命令并将事件存储到事件存储库,然后由eventstore的调度程序在总线上发布.然后,读取模型服务器订阅这些事件以更新读取模型.没有什么花哨的,几乎是书本.

它正在工作,但只是在简单的测试中,当事件存储到EventStore时,我在域服务器上获得了大量的并发异常(间歇性).它正确地重试,但有时它会达到5次重试限制,并且命令最终会出现在错误队列中.

我在哪里可以开始调查以查看导致并发异常的原因?我删除了调度程序,只关注存储事件,它有同样的问题.

我正在使用RavenDB来持久化我的EventStore.我没有做任何花哨的事,只是这样:

using (var stream = eventStore.OpenStream(entityId, 0, int.MaxValue))
{
  stream.Add(new EventMessage { Body = myEvent });
  stream.CommitChanges(Guid.NewGuid());
}
Run Code Online (Sandbox Code Playgroud)

异常的堆栈跟踪如下所示:

2012-03-17 18:34:01,166 [Worker.14] WARN NServiceBus.Unicast.UnicastBus [(null)] <(null)> - EmployeeCommandHandler处理消息失败.EventStore.ConcurrencyException:抛出了类型'EventStore.ConcurrencyException'的异常.at EventStore.OptimisticPipelineHook.PreCommit(提交尝试)在c:\ Code\public\EventStore\src\proj\EventStore.Core\OptimisticPipelineHook.cs:第55行在EventStore.OptimisticEventStore.Commit(提交尝试)在c:\ Code\public\EventStore\src\proj\EventStore.Core\OptimisticEventStore.cs:在C:\ Code\public\EventStore\src\proj\EventStore.Core\OptimisticEventStream.cs中的EventStore.OptimisticEventStream.PersistChanges(Guid commitId)的第90行:第168行在EventStore.OptimisticEventStream.CommitChanges(Guid commitId)的c:\ Code\public\EventStore\src\proj\EventStore.Core\OptimisticEventStream.cs:第149行,在CQRSTest3.Domain.Extensions.StoreEvent(IStoreEvents eventStore,Guid entityId) ,对象evt)在C:\ dev\test\CQRSTest3\CQRSTest3.Domain\Extensions.cs:第13行,位于C:\ dev\test\CQRSTest3\CQRSTest3中的CQRSTest3.Domain.ComandHandlers.EmployeeCommandHandler.Handle(ChangeEmployeeSalary message). Domain\ComandHandlers\Emplo yeeCommandHandler.cs:第55行

Mat*_*int 10

我想到了.不得不挖掘源代码来找到它.我希望这更好地记录下来!这是我新的eventstore连线:

EventStore = Wireup.Init()
          .UsingRavenPersistence("RavenDB")
          .ConsistentQueries()
          .InitializeStorageEngine()
          .Build();
Run Code Online (Sandbox Code Playgroud)

我必须添加.ConsistentQueries(),以便raven持久性提供程序在内部使用WaitForNonStaleResults对查询eventstore进行raven.

基本上当我添加一个新事件,然后尝试在raven赶上索引之前添加另一个事件时,流修订版本不是最新的.第二个事件将踩到第一个事件.