我正在使用EventStore,事情似乎正在起作用,事件由我的内存代理存储和调度,事件由我的读模型处理 . 但是EventStore Commits表中的“dispatched”标志由于某种原因没有设置,因此每次重新启动应用程序时它都会重放所有事件 . 我正在使用SQL Server 2012作为商店 . 没有发生错误 . 知道为什么这个标志不会被设置?
我的代码:
private static IStoreEvents BuildEventStore(IBroker broker)
{
return Wireup.Init()
.UsingSqlPersistence(Constants.EventStoreConnectionStringName)
.InitializeStorageEngine()
.UsingJsonSerialization()
.Compress()
.UsingAsynchronousDispatchScheduler()
.DispatchTo(new DelegateMessageDispatcher(c => DispatchCommit(broker, c)))
.Build();
}
private static void DispatchCommit(IBroker broker, Commit commit)
{
foreach (var @event in commit.Events)
{
if(!(@event.Body is IDomainEvent))
{
throw new InvalidOperationException("An event was published that is not an IDomainEvent: " + @event.Body.GetType());
}
broker.Publish((IDomainEvent)@event.Body);
}
}
1 回答
UsingAsynchronousDispatchScheduler
在调度程序中连接,它在处理的主线之外执行自己的操作 . 例如,如果它有写入问题,命令处理线程将不会听到它 .使生活变得简单不同的一种方法是将其更改为同步,以便您的命令处理链能够听到异常(请记住,调度异常不会回滚命令得到处理且事件现在已经发生的事实) .
但实际上你需要USL看看
UsingAsynchronousDispatchScheduler
处理器连接的内容是否会报告问题,以便你的监控可以解决问题 .