title: nestjs event-based messaging with 1 producer and 2 consumers
body: <p>With nestjs microservices, you can send messages and <strong>receive</strong> the result using request/response-based approach. That is implemented with a combination of <code>@MessagePattern</code> and <code>client.send('my_pattern', myData)</code>. For an example see the nest docs: <a href="https://docs.nestjs.com/microservices/basics#request-response" rel="noreferrer">https://docs.nestjs.com/microservices/basics#request-response</a> and <a href="https://docs.nestjs.com/microservices/basics#sending-messages" rel="noreferrer">https://docs.nestjs.com/microservices/basics#sending-messages</a>.</p>
  <p>How do I receive the result in the event-based approach?</p>
  <p>Suppose you have a user microservice and an auth microservice. Whenever a user is created you want an auth subject to be created as well (saving the username and a hash of the password, so that the user may login with an api request to the auth microservice instead of the user service).</p>
  <p><strong>auth/auth.controller.ts</strong></p>
  <pre><code>  @EventPattern('EVT_USER_CREATED')
    public async handleUserCreated(data: any): Promise&lt;AuthSubject&gt; {
      if (!data.username || !data.password) {
        throw new RpcException('Auth subject must supply username and password');
      } 
      const newSubject: CreateAuthSubject = {
        username: data.username,
        password: data.password,
        email: data.email ?? '',
      };
      const sub = await this.subjectService.create(subject);
      return sub;
    }
  </code></pre>
  <p><strong>user/user.controller.ts</strong></p>
  <pre><code>  @Post('')
    @ApiBody({ type: CreateUser })
    @ApiCreatedResponse({ type: User })
    public async create(@Body() user: CreateUser): Promise&lt;User&gt; {
      const newUser = await this.userService.create(user);
  
      this.userQueue
        .emit&lt;any, CreateUser&gt;('EVT_USER_CREATED', user)
        .subscribe((res) =&gt; {
          console.log(res);   // undefined
        });
  
      return newUser;
    }
  
  </code></pre>
  <p>To verify that there is no error in my setup, I changed <code>@EventPattern</code> to <code>@MessagePattern</code> and <code>this.userQueue.emit&lt;...</code> to <code>this.userQueue.send&lt;...</code>. It worked, i.e. res was a valid auth subject with username and password as expected. However, with the event-based approach outlined in this question <code>res</code> is <strong>always</strong> <code>undefined</code> (whether or not the auth controllers <code>handleUserCreated</code> returns or throws).</p>
  <p>Ultimately I would like to achieve the following: If another microservice needs to process 'EVT_USER_CREATED' events, I just add a <code>@EventPattern('EVT_USER_CREATED') public async handleUserCreated</code> method to its controller. The observable <code>this.userQueue.emit&lt;any, CreateUser&gt;('EVT_USER_CREATED', user)</code> would then receive both results: Once for each of the microservices consuming the user created event.</p>
  <p>So suppose I add a third microservice: the customer microservice that is responsible for saving payment information, the history of orders, etc. Like the auth service it subscribes to 'EVT_USER_CREATED'.</p>
  <p><strong>customer/customer.controller.ts</strong></p>
  <pre><code>  @EventPattern('EVT_USER_CREATED')
    public async handleUserCreated(data: any): Promise&lt;AuthSubject&gt; {    
      const customer = await this.customerService.create(data);
      return customer ;
    }
  </code></pre>
  <p>Now with the above setup the microservices auth and customer will alternate in receiving the events: If the user microservices emits the creation of a user, only the auth service will react to it and create an auth subject from hat user. No customer will be created for that user. For the next user that is created in the user microservice, only a customer will be created but not an auth subject. The third created user will again be consumed by the auth microservice but not by the customer microservice. And so on.</p>
  <pre><code>                                           -- auth microservice 
                                           /
  user microservice --- message broker ---
                                           \
                                             -- customer microservice
  </code></pre>
  <p>To summarize: How do I achive the messaging architecture shown in the diagram, such that I only need one <code>emit(...)</code> call in the <code>user.controller.ts</code> and, such that I reveive both responses in the subscrption to the <code>emit(...)</code> call?</p>