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);
}
}