I'm using EventStore and things appear to be working, the event is stored and dispatched by my in-memory broker, the event is processed by my read model. But the "dispatched" flag in the EventStore Commits table is not getting set for some reason, so each time I restart my app it replays all of the events. I'm using SQL Server 2012 as the store. No errors are occurring. Any idea why this flag would not be getting set?
My code:
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);
}
}