質問

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);
        }
    }
役に立ちましたか?

解決

UsingAsynchronousDispatchScheduler wires in a dispatcher that does its own thing out of the mainline of your processing. For example, if it has issues writing, the command processing thread is not going to hear about it.

One way of making life simplerdifferent is to change it to synchronous so your command processing chain gets to hear about the exceptions (remember that a dispatch exception doesn't roll back the fact that the command got processed and the event has now happened though).

But really you need to USL to see what the processor wired in by UsingAsynchronousDispatchScheduler does wrt reporting problems so that your monitoring can pick up the issue.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top