cqrs icon indicating copy to clipboard operation
cqrs copied to clipboard

Aggregate event streams

Open adriano-di-giovanni opened this issue 3 years ago • 1 comments

I'm submitting a...


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Persisting events using external stores such as Event Store happens by appending them to a stream. The stream groups all events related to a particular instance of an aggregate root. The stream name usually is <AggregateRoot>-<id>.

At the moment, the stream name/id information has to be bundled with the event.

Expected behavior

It would be great to introduce the concept of stream name/id at the AggregateRoot level

export abstract class AggregateRoot<EventBase extends IEvent = IEvent> {
  // ...
  protected get streamId(): string {
    return void 0
  }

  publish<T extends EventBase = EventBase>(event: T, streamId?: string) {}
}

Such change would also impact

  • the IEventBus and IEventPublisher interfaces
  • the EventPublisher

If streamId is optional, the change is non-breaking.

adriano-di-giovanni avatar Jun 04 '21 09:06 adriano-di-giovanni

Wrapping the event and passing the streamId as metadata to the event envelope (which also extends IEvent) may solve the problem.

the event handler can be decorated as follow:

@EventsHandler(Envelope<OriginalEvent>)

(just started looking into nestjs and CQRS module... hope I'm not messing up)

redaLaanait avatar Oct 17 '22 20:10 redaLaanait