[英]Why does nestjs framework use a transport layer different than HTTP in a microservices approach?
If you look a the OSI model, HTTP is part of Layer 7 (Application).如果您查看 OSI 模型,HTTP 是第 7 层(应用程序)的一部分。 TCP is Layer 4 (Transport).
TCP 是第 4 层(传输)。
When looking at Layer 4 there is no determining characteristic that makes it HTTP, AMPQ, gRPC, or RTSP.在查看第 4 层时,没有决定性特征使其成为 HTTP、AMPQ、gRPC 或 RTSP。 Layer 4 is explicitly how data is transmitted and received with the remote device.
第 4 层明确说明了远程设备如何传输和接收数据。
Now, this is where networking and the software development worlds collide.现在,这就是网络和软件开发世界碰撞的地方。 Networking people will use "transport" meaning Layer 4, while Programming people use "transport" meaning the way a packet of data is transmitted to another component.
网络人员将使用“传输”表示第 4 层,而编程人员使用“传输”表示将数据包传输到另一个组件的方式。
The meaning of "transport" (or "transporter" as used in the docs) is used as an abstraction from how messages are shared in this architecture. “传输”(或文档中使用的“传输器”)的含义被用作此架构中如何共享消息的抽象。
Looking at the documentation if you are looking for something like AMPQ for your microservice you can use NATS or REDIS (both implementations are built by them).如果您正在为您的微服务寻找类似 AMPQ 的东西,请查看文档,您可以使用NATS或REDIS (这两种实现都是由它们构建的)。
https://docs.nestjs.com/microservices/basics#getting-startedhttps://docs.nestjs.com/microservices/basics#getting-started
The main reason is it is slow.主要原因是速度慢。 The problem with HTTP approach is that, with HTTP, JSON can generate an unwanted processing time to send and translate the information.
HTTP 方法的问题在于,使用 HTTP,JSON 会产生不需要的处理时间来发送和翻译信息。
One problem with http-json is the serialization time of JSON sent. http-json 的一个问题是发送的 JSON 的序列化时间。 This is an expensive process and imagine serialization for a big data.
这是一个昂贵的过程,想象一下大数据的序列化。
In addition to JSON, there are a number of HTTP headers that should be interpreted further which may be discarded.除了 JSON 之外,还有许多 HTTP 标头需要进一步解释,这些标头可能会被丢弃。 The only concern should be to maintain a single layer for sending and receiving messages.
唯一需要考虑的是维护一个用于发送和接收消息的层。 Therefore, the HTTP protocol with JSON to communicate between microservices is very slow.
因此,使用 JSON 的 HTTP 协议在微服务之间进行通信非常慢。 There are some optimization techniques and those are complex and does not add significant performance benefits
有一些优化技术,这些技术很复杂,不会增加显着的性能优势
Also,HTTP spends more time waiting than it does transfer data.此外,HTTP 等待的时间比它传输数据的时间要长。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.