NEventStore RavenDB - Obtain Commit Data

213 views Asked by At

I'm working through a basic example of working with NEventStore with RavenDB and I've hit a stumbling block.

I've managed to succesfully commit my events to the RavenDB datasource, but now I need to pull them back out, to replay them (CQRS - ES) pattern.

I can bring back the Collection of EventMesssage objects by usng the NEventStore IStoreEvents Unterface like this :-

public IEnumerable<EventMessage> GetEvents(Guid aggregateRootId)
        {
            using (var stream = _store.OpenStream(aggregateRootId, 0))
            {
                return stream.CommittedEvents;
            }

        }

In each EventMessage, I can access the Header & the Body Properties. In the body property is the actual event that i have submitted, which i want to pull out and inspect.

I'm not sure if what I'm trying to achieve is correct.

Should I be using the Raven IDocumentStore class to retrieve the event objects or should this be done via NEventstore Stream.

1

There are 1 answers

0
wilver On

At basic level what you're doing is correct: it's the same code shown in the quick-start NEventstore sample code. If you work in a more DDD context, probably you should emit events from your Aggregates using the CommonDomain library that is embedded in NEventStore, and retrieve them from IRepository Interface.

You could find some example in the web. One of them is a my training project: https://github.com/williamverdolini/CQRS-ES-Todos (some notes about that). I'm not using RavenDB and I'm still learnig...but could be useful ;-)