Skip to content

Set event ID when persisting messages#247

Closed
axlon wants to merge 1 commit intoEventSaucePHP:mainfrom
axlon:event-sourced-aggregate-root-repository-event-id
Closed

Set event ID when persisting messages#247
axlon wants to merge 1 commit intoEventSaucePHP:mainfrom
axlon:event-sourced-aggregate-root-repository-event-id

Conversation

@axlon
Copy link
Contributor

@axlon axlon commented Feb 10, 2026

Alternative to EventSaucePHP/MessageStorage#38

Currently when a message is persisted, the event ID is not set until the very last moment (when the message is inserted into the database). This causes outbox repositories and message dispatchers to receive message instances that do not have this header set.

This PR changes the EventSourcedAggregateRootRepository to always set the event ID when constructing messages, so that repositories, outboxes and dispatchers always receive the same message headers. Unlike EventSaucePHP/MessageStorage#38, this covers both message repositories and dispatchers, the downside to this approach is that if someone uses a decorator to generate their own event IDs the aggregate root repository will now do useless work

@frankdejonge
Copy link
Member

The way to pull this forward is to use a MessageDecorator. The package ships with a UuidMessageDecorator, which adds a UUID as the event ID, I just shipped a UuidV7 implementation, so you can use V4 of V7 or create one yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants