-
Notifications
You must be signed in to change notification settings - Fork 2
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
Local event bus (mediator pattern) #15
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #15 +/- ##
==========================================
+ Coverage 62.41% 70.83% +8.41%
==========================================
Files 7 10 +3
Lines 149 192 +43
Branches 29 37 +8
==========================================
+ Hits 93 136 +43
Misses 53 53
Partials 3 3 ☔ View full report in Codecov by Sentry. |
|
@gtoselli I preferred to use a class like we did in the past with PublicEvent anyway the library is compatible with a plain object that matches the interface, what do you think? |
@lucagiove Did you get the code from Golee? The names could be better. Messages passing from the bus must be deserialized to json. So even if we used classes they would go parsed. Does it make sense? |
Partially yes.
Since this is a ddd toolkit I think we should use domain names like "event" instead of message. Moreover this could be an external interface, internally there might be a more infrastructural layer where events are converted to messages. Since it's not a real bus maybe we could use something like:
Mah it's a matter of taste, I prefer classes to enforce different type not based on name strings. I'm wondering whether we should enforce an event field for the AggregateId or Id, what do you think? |
That makes sense, but my point is another.
The application could probably have a DomainEvent class (which is a special kind of message) that requires an aggregateId field. Since this library is a toolkit, it should offer things as generic as possible that everyone can use as they wish. |
@lucagiove I found a little error that I fix with commit b57a0dd. The problem was that the subscribe method takes an instance of the Event class and not the class itself as second argument: Before eventBus.subscribe(new FooEventHandlerOk(), new FooEvent({ foo: 'bar' })); After eventBus.subscribe(new FooEventHandlerOk(), FooEvent); |
With commit 3a2c794 I made asynchronous handlers execution towards |
With commit 2d18c84 I introduce a simple retry mechanism. All attempts are logged with warn level. If all attempts fail a message is logged with level error. This allows us to configure log-side alarms (like dead-letter-queue tecnique). In the commit 08de05d I added a super simple exponential backoff mechanism. If you read these pr comments first you might be worried that this local-event-bus is getting too complicated. |
It is getting too complicated but code is simple. |
Right but this forces to use the class :( Doing something like this does not make sense anyway? subscribe<E extends IEvent<unknown>>(handler: IEventHandler<E>, event: Pick<E, 'name'>): void; Other option is to rely on a string for the event name, maybe more generic.. |
I implemented |
No description provided.