What is an Aggregate Function?

萝らか妹 提交于 2019-12-24 10:30:25

问题


I am trying to learn Event Sourcing (using Greg Youngs Event Store) in my spare time. I have setup a simple stream and I can read from it and write to it.

Please see this link: https://eventstore.org/docs/getting-started/?tabs=tabid-1%2Ctabid-dotnet-client%2Ctabid-dotnet-client-connect%2Ctabid-4. It says:

"If you are Event Sourcing a domain model, a stream equates to an aggregate function."

I don't believe I have ever come across the term Aggregate Function before - I know aggregate root and aggregate, however not aggregate function. Say I have the events below:

BookingCreatedEvent
BookingUpdatedEvent

If I was to create an event log in SQL server then it could look something like this (the Cargo column contains the serialized object):

What Event streams would I have in Event Store for this? I was reading an answer from a user on here who seems to be very knowledgeable about Event Sourcing and he suggested the following:

AggregateType+AggregateId+Version

On that basis believe the events would be named as follows:

BookingCreatedEvent511 (51 is the aggregate ID and 1 is the version)
BookingUpdatedEvent511 (51 is the aggregate ID and 1 is the version)
BookingUpdatedEvent512 (51 is the aggregate ID and 2 is the version)
BookingCreatedEvent521 (52 is the aggregate ID and 1 is the version)
BookingUpdatedEvent513 (51 is the aggregate ID and 3 is the version)
BookingCreatedEvent531 (53 is the aggregate ID and 1 is the version)
BookingUpdatedEvent514 (51 is the aggregate ID and 4 is the version)
BookingUpdatedEvent515 (51 is the aggregate ID and 5 is the version)
BookingUpdatedEvent516 (51 is the aggregate ID and 6 is the version)
BookingUpdatedEvent517 (51 is the aggregate ID and 7 is the version)

Therefore there are 10 event streams. This looks a little confusing i.e. concatenating the aggregate ID and version - for example, say I had the following:

  BookingUpdatedEvent51745

How would I know what part of 51745 is the aggregate ID and what part is the version.

Have I understood this correctly?


回答1:


If you are Event Sourcing a domain model, a stream equates to an aggregate function

I can't find any evidence that means anything.

The original text of that section of the document, committed by Dan Leech in 2014, used this spelling

If you are Event Sourcing a domain model a stream would equate to an aggregate.

The commit where Chris made the change is available in github, but it's mixed in with a major rewrite, so there's no documented explanation for the change.

Say I had an Aggregate of order (containing order items) and there were 1 million of them, then I would have 1 million streams instead of 1

Basically, yes.

More precisely, each stream is logically isolated from all of the others; Event Store doesn't give you facilities to make atomic changes to more than one stream at a time.

So each immediately consistent transaction in your domain model should be writing to exactly one event stream.



来源:https://stackoverflow.com/questions/52382927/what-is-an-aggregate-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!