79208669

Date: 2024-11-20 19:30:02
Score: 0.5
Natty:
Report link

Nest Nats suuports two way out from box, you just need to configure MessagePattern https://docs.nestjs.com/microservices/basics#request-response

// service 1: data-source controller

@Controller()
export class AppController {
  constructor(
    @Inject(NATS) private readonly nats: ClientNats,
  ) {}

  @MessagePattern('data-source.status')
  async status() {
    return 'Ok!';
  }
}
// service 2 somewere in the code...

import { firstValueFrom } from 'rxjs';
...
const req = this.nats.send('data-source.status', {});
const res = await firstValueFrom(req).catch((e) => console.error(e));
console.log({ res });
...
// out
{ res: 'Ok!' }
Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: mat.twg