Skip to content
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

Event stream handling enhancements #445

Merged
merged 17 commits into from
Jul 16, 2024
Merged

Conversation

subhashb
Copy link
Contributor

@subhashb subhashb commented Jul 10, 2024

This PR contains changes to enable Event Handlers to operate on a stream and derive event class from the type in the event data.

In the first iteration of Protean, event classes will need to be placed in a separate shared package accessible to the domain producing the event and all domains consuming the event. In later iterations, we will replace the shared event directory with a schema registry, and domains will be able to generate event classes from schemas.

@subhashb subhashb self-assigned this Jul 10, 2024
Copy link

codecov bot commented Jul 10, 2024

Codecov Report

Attention: Patch coverage is 97.15640% with 6 lines in your changes missing coverage. Please review.

Project coverage is 89.03%. Comparing base (44f5919) to head (b9feafd).
Report is 1 commits behind head on main.

Files Patch % Lines
src/protean/fields/association.py 76.47% 1 Missing and 3 partials ⚠️
src/protean/server/subscription.py 66.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #445      +/-   ##
==========================================
+ Coverage   88.91%   89.03%   +0.12%     
==========================================
  Files          71       71              
  Lines        5981     6039      +58     
  Branches     1187     1212      +25     
==========================================
+ Hits         5318     5377      +59     
  Misses        492      492              
+ Partials      171      170       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

subhashb added 14 commits July 10, 2024 07:08
This is done on registration because `domain.name` is a part of the
event type string. Ex. `Customer.Registered.v1`.
We were basing the logic on retrieving handlers on the fully
qualified name of the event or command class. This commit moves
the logic to be on the `__type__` attribute of event/command
classes.

This is one of the steps necessary to be able to handle events/
messages from other systems, where we may not have an event
registered in the domain. It is also necessary to be able to
support multiple versions of event and command classes.
Factory methods in command handler and event handler were parsing
the methods marked with `handle()` and setting up command and
event structure for later processing. This has now been moved to
`Domain.init()` method because events and commands are not yet
ready when command and event handlers are registered.
Also, retain `stream_name` as the field in Message and Event store implementations.
We will change this when we push message construction and processing to each
event store's implementation.
- Do not allow associations and references in Events and Commands
- Use camelcase domain name when constructing event/command type
- Validate ValueObject field is connected to a value object
- Refactor repository methods to indicate support for both aggregates and views
Use the `__type__` value present in events and commands to retrieve
event and command classes from domain, instead of fetching by
fully qualified name. This change is required to support cross-domain
event processing.

Also:
- Fix bug with collecting identity value in associations
- Remove unused delist functionality in registry
This commit allows external events to be registered in a domain to allow
processing incoming events. The event is only stored in a cache mapped by
event types, and does not update the registry.
@subhashb subhashb merged commit 0a1bf49 into main Jul 16, 2024
6 checks passed
@subhashb subhashb deleted the event-stream-handling-enhancements branch July 16, 2024 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant