#Eventpattern works but messagepattern is not hitting the microservice

2 messages · Page 1 of 1 (latest)

balmy nymph
#

Client:

import { Injectable } from '@nestjs/common';
import { Inject } from '@nestjs/common';

import { ClientProxy } from '@nestjs/microservices/client';
@Injectable()
export class AppService {
  constructor(@Inject('NOTIFY_SERVICE') private client: ClientProxy) {}

  createUserEventPattern(): string {
    this.client.emit('USER_CREATED', 'Jannik');
    return 'Hello World!';
  }
  createUserMessagePattern(): string {
    this.client.send({ cmd: 'USER_CREATED' }, 'Jannik');
    return 'Hello World!';
  }
}

Microservice:

import { Controller } from '@nestjs/common';
import { EventPattern, MessagePattern } from '@nestjs/microservices';

@Controller('mail')
export class MailController {
  @EventPattern('USER_CREATED')
  userCreatedEventPattern(data: string): string {
    console.log('NOTIFY-SERVICE _USER CREATED EVENT');
    console.log(data);
    return 'Email sent to user + ' + data;
  }
  //
  @MessagePattern({ cmd: 'USER_CREATED' })
  userCreatedMessagePattern(data: string): string {
    console.log('NOTIFY-SERVICE _USER CREATED MESSAGE');
    console.log(data);
    return 'Email sent to user + ' + data;
  }
}

why is my messagepattern not receiving the data? eventpattern works fine

rustic wedge
#

For the message pattern decorators, the observable is cold so you need to subscribe to it