Reputation: 308
I'm looking at joliver's EventStore and thinking about replaying events for a new event handler. I see there's a method to get all the commits since a certain point in time (ICommitStreams.GetFrom(Date)) but I can't figure out how to only get events of a specific type.
Am I missing something?
Upvotes: 3
Views: 378
Reputation: 17176
Just for reference, this is what I do:
var typesToSend = typeof (MyApp.Messages.Events.SomeAggregate.SomeEvent).Assembly
.GetTypes()
.Where(t => t.Namespace != null && t.Namespace.StartsWith("MyApp.Messages.Events.SomeAggregate"))
.ToList();
var commits = eventStore.Advanced.GetFrom(DateTime.MinValue)
.Where(c => c.Events.Any(e => typesToSend.Contains(e.Body.GetType())))
.OrderBy(c => c.CommitSequence)
.ToList();
As Jonathan states, a commit may contain more than one event and this gets all commits that contains at least one of the events I'm looking for. To filter further, you will have to look at each event in the commits.
Upvotes: 3
Reputation: 5267
The EventStore itself doesn't particularly care what is committed which means that, by itself, it doesn't track individual event types for each commit.
There are several reasons for this. One is simplicity and another is the ability to support virtually any storage engine. I wanted to keep the design extremely simple and the model very clean. Further I wanted to avoid being too demanding of the underlying storage engine which may or may not support indexing. If you're going to query on a specific type, you're already assuming that the underlying storage engine delivers indexing. Since the EventStore is storage engine agnostic, the two don't mix.
The other thing is that a "commit" is actually a set of one or more events. When you load a commit, you get all events.
One possible solution is just to load everything since a point in time and then ignore the events that you don't care about. Another solution is to have a subscriber that listens to all messages coming out of the EventStore that (asynchronously/on another thread) pushes the messages into persistent storage by with the appropriate indexing on event type. The correct answer depends upon your performance requirements.
Upvotes: 2