DEV Community

Perm Chao
Perm Chao

Posted on

2

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

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay