DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป

Mossie Chao
Mossie Chao

Posted on

NestJS Micro-services 101 Part 1 - Try to communicate btw two services

I try to learn NestJS Framework to make micro-services

Objective in Part 1

send simple message from one service to another service

// Project 1 api-gateway
nest new api-gateway

// Project เธ—เธตเนˆ 2 user-service
nest new user
Enter fullscreen mode Exit fullscreen mode

User Request (http://localhost:3000) -> API Gateway -> User


Difference btw bootstrap in api-gateway and user

api-gateway main.ts
api-gateway

user main.ts
user


api-gateway service will know user service by register in api-gateway module

api-gateway-module


so you can declare user service proxy in constructor to send data into it, by
hello is event pattern

user-service-send


user service controller will receive event pattern name hello by use EventPattern decorator

user-controller


So, this is response
response


Full code https://github.com/mossnana/nestjs/tree/microservices

Top comments (0)

This post blew up on DEV in 2020:

js visualized

๐Ÿš€โš™๏ธ JavaScript Visualized: the JavaScript Engine

As JavaScript devs, we usually don't have to deal with compilers ourselves. However, it's definitely good to know the basics of the JavaScript engine and see how it handles our human-friendly JS code, and turns it into something machines understand! ๐Ÿฅณ

Happy coding!