New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Publish a DomainEventMessage outside of an aggregate #510
Comments
Hi @RobWin, Interesting use case you've got there. Typically I'd not be overly enthusiastic to let outside sources influence your aggregates, but this seems a little different from the other use cases I've come across. So, what I'd suggest to do is the following:
The only caveat to this is that the Would this solution work out for you @RobWin? |
Yes, but how can I make sure that the sequenceNumber is not increased in parallel by another node/thread? |
What is the reason that EventStore#publish does not increase the sequenceNumber? |
Since atomic counters (sequence numbers) in distributed systems are slow and difficult to implement, wouldn't it be possible that Isn't the sequence number anway an implementation detail of the Eventstore? The event producer should not know anything about this. Only event consumers are interested in the offset. |
Hi Robert, I think you may be mixing up two different things here. The sequence number is used by an Aggregate as it emits events to ensure its internal consistency. It is not used by the event store to order events globally. Since an Aggregate is a unit of consistency (by definition of Domain Driven Design), there shouldn't normally be any conflicts here. An Aggregate is responsible for maintaining its own state. Consumers don't need this sequence number. They either subscribe to Events (using a You said "As a User of an API I don't want to handle incremental sequence numbers :(". Good news: you don't, normally. If you implement an aggregate, all you need to do is Hope this clarifies things. |
Hi, thank you for your clarification. Our scenario looks as follows. I guess I have to translate incoming event messages from devices into commands which are handled by a device aggregate (digital twin) which itself emits/applies a similar internal event. It's like simulating the real communication. Seems fine to me. |
Hi guys I think that I have similar problem. Concretely I use sagas to handle payment transaction. My scenario is following:
When PaymentExpiredEvent occurs it is stored into db where event identifier is same as aggregate identifier column . That means that such event can not be used during event sourcing of my aggregate. Q: Am I right? Is this correct behaviour? If so, what I can do as RobWin mentioned is to trigger another PaymentExpiredCommand from saga and create similar ExpiredEvent which will be joind with aggregate. But I want to avoid this if possible. Q: What can I do? thank you very much |
Hello,
it's more a question or feature request than an issue.
I'm working in the Smart Home/IoT-domain and our system consumes events (messages) from gateways/devices via AMQP. The events represent domain events and we want to store them in the event store (keyword: event sourcing). Gateways/devices are our aggregate roots and we want to able to reconstruct their state based on events (keyword: digital twins).
I need a way to apply a
GenericDomainEventMessage
outside of an aggregate. The simplest solution would be to to use theEventBus
to publish theGenericDomainEventMessage
. The Event Message could have a field with an@TargetAggregateIdentifier
annotation. TheEventBus
then knows how to set the aggregateIdentifier in the event store and how to increase the sequenceNumber.What do you think?
The text was updated successfully, but these errors were encountered: