微服务和 http 服务之间用 TCP 通信。

[](https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/fb35810637d44f54977cb76e89a13d6f~tplv-k3u1fbpfcp-zoom-in-crop-mark:1512:0:0:0.awebp?)

用 nest 跑个微服务的步骤如下:

这就是 Nest 跑微服务的方式。

各自启动自己

然后main 使用 clientsModule 注册其他两个服务

参考代码

GitHub - xiaoqiao112/nest-ms: 微服务架构,主项目和微服务项目分开

https://github.com/QuarkGluonPlasma/nest-microservice-demo.git

服务间通讯协议

Nest 内置了几种不同的微服务传输层实现,它们定义在 @nestjs/microservices 包的 Transport 模块内,我们简单的进行归类: