nestjs / cqrs

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

Double events when using microservice #1393

Open ivcosla opened 1 year ago

ivcosla commented 1 year ago

Is there an existing issue for this?

Current behavior

When NestFactory is used to build a microservice app, and then init is called for it, any attempt to send a message through the EventBus will result in the EventsListener's being called twice with the event.

Minimum reproduction code

https://gist.github.com/ivcosla/908e717af746801787cced1f80c1c327

Steps to reproduce

  1. Copy/paste the shared gist into any project.
  2. Run the test.

Expected behavior

The EventsHandler's for the emitted event should be called only once.

Package version

10.0.0

NestJS version

10.0.0

Node.js version

20.3.0

In which operating systems have you tested?

Other

No response

ivcosla commented 1 year ago

If I comment this line: https://github.com/nestjs/nest/blob/master/packages/microservices/nest-microservice.ts#LL159C13-L159C13 the event is emitted only once.

ivcosla commented 1 year ago

NestApplication doesn't calls super.init() inside it's init() method, whereas NestMicroservice does. Maybe is that it?.