Hi,
We using nestjs-cls for all over the places of our backend and @transactional really solved tx propagation on request pipeline. As we actively using @nestjs/cqrs I guess there could be an option as Spring offer like TransactionalEventPublisher that binds to current tx execution and postpone event publish until commit.
Is there any options to do the same thing for nestjs-cls/transactional?
Probably it could be something like Observable that receives callbacks that fire events in them same order as received.
// When transaction initialised we create ReplaySubject as storage for all events.
const afterCommitEvents = new ReplaySubject<DomainEvent>();
// During transaction - events buffered in order
this.txHost.tx.afterCommitEvents.next(new ProjectCreatedEvent(...));
this.txHost.tx.afterCommitEvents.next(new WalletCreatedEvent(...));
// Once transaction commited and connection released proceeding all stored events.
afterCommitEvents.subscribe(event => this.eventBus.publish(event));
afterCommitEvents.complete();
Pros:
- Confidence that events are triggered when transaction succeed
Cons:
- nestjs-cls/transactional will depend on @nestjs/cqrs.
Comments:
Not sure how we can avoid dependency on cqrs package, but it could be just a feature requirement tbh and we can go with that.
Hi,
We using nestjs-cls for all over the places of our backend and @transactional really solved tx propagation on request pipeline. As we actively using @nestjs/cqrs I guess there could be an option as Spring offer like TransactionalEventPublisher that binds to current tx execution and postpone event publish until commit.
Is there any options to do the same thing for nestjs-cls/transactional?
Probably it could be something like Observable that receives callbacks that fire events in them same order as received.
Pros:
Cons:
Comments:
Not sure how we can avoid dependency on cqrs package, but it could be just a feature requirement tbh and we can go with that.