nestjs / cqrs

A lightweight CQRS module for Nest framework (node.js) :balloon:
https://nestjs.com
MIT License
849 stars 150 forks source link

Command/query publisher is never called #853

Closed bpawel10 closed 2 years ago

bpawel10 commented 2 years ago

Is there an existing issue for this?

Current behavior

Hi,

I wanted to use custom publisher for commands, events and queries, but it doesn't work. If I connect my own publisher in onModuleInit method this.command$.publisher = this.commandPublisher; and then in a controller call this.commandBus.execute(...), my publisher won't be called, because this publisher is never called in the command bus class. To make it work, I have to manually call this.commandBus.publisher.publish(...).

Minimum reproduction code

https://github.com/nestjs/cqrs/blob/master/src/command-bus.ts

Steps to reproduce

No response

Expected behavior

I think we should move these two lines

this.subject$.next(command);
return handler.execute(command);

from command bus execute method to default publisher and instead add this._publisher.publish(...) there. This way it would work fine for both default and custom publisher.

And the same applies to query bus.

Package version

8.0.1

NestJS version

8.2.3

Node.js version

No response

In which operating systems have you tested?

Other

No response

kamilmysliwiec commented 2 years ago

Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.