Search code examples
eventstoredb

Where in the Admin site of EventStore I can view my saving events?


By the way how do you create a STREAM?

I use AppendToStreamAsync directly, is this right or shall I create a stream first then append onto this stream?

I also tried performing some tests but using the methods below I can write events onto EventStore but can't read Events from it.

And most import question is how do I view my saving events in the Admin site of EventStore?

Here are the code:

    public async Task AppendEventAsync(IEvent @event)
    {
        try
        {
            var eventData = new EventData(@event.EventId, 
                @event.GetType().AssemblyQualifiedName, 
                true, 
                Serializer.Serialize(@event), 
                Encoding.UTF8.GetBytes("{}"));

            var writeResult = await connection.AppendToStreamAsync(
                   @event.SourceId.ToString(),
                   @event.AggregateVersion,
                   eventData);

            Console.WriteLine(writeResult);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
        }
    }


    public async Task<IEnumerable<IEvent>> ReadEventsAsync(Guid aggregateId)
    {
        var ret = new List<IEvent>();
        StreamEventsSlice currentSlice;
        long nextSliceStart = StreamPosition.Start;

        do
        {
            currentSlice = await connection.ReadStreamEventsForwardAsync(aggregateId.ToString(), nextSliceStart, 200, false);
            if (currentSlice.Status != SliceReadStatus.Success)
            {
                throw new Exception($"Aggregate {aggregateId} not found");
            }
            nextSliceStart = currentSlice.NextEventNumber;
            foreach (var resolvedEvent in currentSlice.Events)
            {
                ret.Add(Serializer.Deserialize(resolvedEvent.Event.EventType, resolvedEvent.Event.Data));
            }
        } while (!currentSlice.IsEndOfStream);

        return ret;
    }

admin


Solution

  • Streams are created automatically as you write events. You should follow the recommended naming convention though as it enables a few features out of the box.

    await Connection.AppendToStreamAsync("CustomerAggregate-b2c28cc1-2880-4924-b68f-d85cf24389ba", expectedVersion, creds, eventData);
    

    It is recommended to call your streams as "category-id" - (where category in our case is the aggregate name) as we use are using DDD+CQRS pattern

    CustomerAggregate-b2c28cc1-2880-4924-b68f-d85cf24389ba

    The stream matures as you write more events to the same stream name.

    The first events ID becomes the "aggregateID" in our case and then each new eventID after that is unique. The only way to recreate our aggregate is to replay the events in sequence. If the sequence fails an exception is thrown

    The reason to use this naming convention is that Event Store runs a few default internal projection for your convenience. Here is a very convoluted documentation about it

    • $by_category
    • $by_event_type
    • $stream_by_category
    • $streams

    By Category

    By category basically means there is stream created using internal projection which for our CustomerAggregate we subscribe to $ce-CustomerAggregate events - and we will see only those "categories" regardless of their ID's - The event data contains everything we need there after.

    We use persistent subscribers (small C# console applications) which are setup to work with $ce-CustomerAggregate. Persistent subscribers are great because they remember the last event your client acknowledged. So if the application crashes, you start it and it starts from the last place that application finished.

    This is where event store starts to shine and stand out from the other "event store implementations"

    Viewing your events

    The example with persistent subscribers is one way to set things up using code.

    You cannot really view "all" your data in the admin site. The purpose of the admin site it to manage projections, manage users, see some statistics, create some projections, and have a recent view of streams and events only. (If you know the ID's you can create the URL's as you need them - but you cant search for them)

    If you want to see ALL the data then you use the RESTfull API using by using something like Postman. Maybe there is a 3rd party software that can create a grid like data source viewer but I am unaware of this. That would probably also just hook into the REST API and you could create your own visualiser this way quite quickly.

    Again back to code, you can also always read all events from 0 using on of the libraries - which incidentally using DDD+CQRS you always read the aggregates stream from 0 to rebuilt its state. But you can do the same for other requirements.

    In some cases looking at how to use snapshots makes replaying events allot faster, if you have an extremely large stream to deal with.

    Paradigm shift

    Event Store has quite a learning curve and is a paradigm shift from conventional transactional databases. Event Stores best friend is CQRS - We use a slightly modified version of the CQRS Lite open source framework

    To truly appreciate Event Store you would need to understand DDD concepts and then dig into CQRS/ES - There are a few good YouTube videos and examples.