Updating Multiple Aggregates Using JOliver EventStore

I have a question regarding updating multiple aggregates in a single transaction using the JOliver Event Store . As far as I understand, each unit should have its own stream of events. Now, although many command handlers will load only one aggregate and update only this aggregate (i.e., save events for these aggregates), I can imagine that there will be command handlers that need to update several aggregates. And of course, I would like to do it in a transactional way.

However, I do not see how to do this with the event repository. Events are stored by calling CommitChanges()in the event stream. If we have several aggregates for updating, they will have several streams of events and, therefore, several calls to CommitChanges(). The only way to make a transaction is to wrap it in TransactionScope, but that doesn't make much sense, since the underlying storage technology may not support transactions. So I end up with this code, which is definitely not what I'm looking for:

        Guid aggregateGuid1 = Guid.NewGuid();
        Guid aggregateGuid2 = Guid.NewGuid();
        Guid commitGuid = Guid.NewGuid();

        var stream = store.OpenStream(aggregateGuid1, 0, int.MaxValue);
        stream.Add(new EventMessage() { Body = new MonitorDisabled { MonitorGuid = aggregateGuid1, User = "A" } });
        stream.CommitChanges(commitGuid);

        stream = store.OpenStream(aggregateGuid2, 0, int.MaxValue);
        stream.Add(new EventMessage() { Body = new MonitorEnabled { MonitorGuid = aggregateGuid2, User = "B" } });
        // Can't commit twice with the same commit id, what if fails after first one? No way for the store to know it had to write the second part of the commit.
        stream.CommitChanges(commitGuid);

It makes me feel like I totally don’t understand how to use the Event Store. Can anyone help me here? Many thanks!

+5
source share
3

.

, , , .

, () , , , , . , . , , , .

+8

, , " ". - . , , , , , .

+3

, .

TransactionScope EventStore:

EventStore NServiceBus . , (MSMQ, SQL Server, Raven ..), EventStore TransactionScopeOption . EventStore , MSDTC, . - NES

Cross operations with RavenDB:

You will receive transactions from my dead, cold, broken hands - Ayende

0
source

All Articles