NestJS tcp微服务负载均衡
我有一个 Nestjs 应用程序,如下:
- 网关 - HTTP
- 微服务 1 - TCP (ms1)
- 微服务 2 - TCP (ms2)
网关调用 ms1 和 ms2。 ms1 和 ms2 是相同的重复微服务。
我想加载 ms1 和 ms2 之间的余额。 在nestjs中如何实现这一点?
谢谢
I have a nestjs app as follows:
- Gateway - HTTP
- Microservice1 - TCP (ms1)
- Microservice2 - TCP (ms2)
Gateway calling ms1 and ms2.
ms1 and ms2 are the same duplicated microservice.
I would like to load the balance between ms1 and ms2.
How do accomplish that in nestjs?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
许多云平台都有内置的负载平衡器,我建议使用它们。从我的角度来看,这个TCP故事存在一个根本的问题。我认为负载平衡器无法正确分发TCP数据包,因为它不知道哪个数据包是逻辑单元的。
由于Nestjs文档说:“ ...从根本上是使用与HTTP不同的传输层的应用程序”,因此您可以简单地创建一个单独运行但仍可以通过HTTP访问的新巢应用程序,因为差异仅在IN中无论如何,运输协议和云内置负载平衡器都可以处理HTTP。
这意味着:
通信通过HTTPModule进行:
Many cloud platforms have a built-in load balancer and I recommend using them. There is a fundamental problem with this TCP story from my point of view. I think that a load balancer could not distribute the TCP packets correctly because it would not know which packets belong together as a logical unit.
Since the NestJS documentation says: "... a microservice is fundamentally an application that uses a different transport layer than HTTP", you could simply create a new Nest application that runs separately but is still accessible via HTTP, because the difference is only in the transport protocol and the cloud built-in load balancer can handle HTTP in any case.
That mean:
Communication goes via the HttpModule: