简体   繁体   English

微服务架构中的HTTP vs Thrift

[英]HTTP vs Thrift in microservices architecture

I'm have just start learning about micro-services and I have a question that I cannot answer myself. 我刚刚开始学习微服务,我有一个问题,我无法自己回答。 (and I'm also a Java based developer) (我也是一名基于Java的开发人员)

I have a situation like this: 我有这样的情况:

  1. I have service A (an API service) that call Thrift services (Named T1) for get data. 我有服务A(API服务)调用Thrift服务(命名为T1)获取数据。

  2. Then I have a service B that can use data response from A, parse these data and then generate some new data, finally, return it to client. 然后我有一个服务B,它可以使用来自A的数据响应,解析这些数据,然后生成一些新数据,最后,将它返回给客户端。

The question is: Which I should use? 问题是:我应该使用哪种? B call API from A and parse (for example JSON data) with HttpClient/ AsyncHttpClient with connection pool or B direct call T1 and repeat what A do? B从A调用API并解析(例如JSON数据)与HttpClient / AsyncHttpClient连接池或B直接调用T1并重复A做什么?

IMHO, I think Thrift (with connection pooling too) is faster than HTTP call? 恕我直言,我认为Thrift(连接池也是)比HTTP调用更快? Am I right? 我对吗?

I see a lot of services that use HTTP for internal like Elastic search, Neo4j, Eureka Netflix, etc ... 我看到很多使用HTTP的内部服务,如弹性搜索,Neo4j,Eureka Netflix等......

So, which one should I use? 那么,我应该使用哪一个? And why HTTP is so popular for internal use instead of RPC like Thrift, ProtoBuf, ...? 为什么HTTP如此受内部使用而不是像Thrift,ProtoBuf那样的RPC,......?

Sorry for my bad english. 对不起,我的英语不好。 Thank you in advance. 先感谢您。

HTTP and JSON or XML are generally used because they're platform and language independent. 通常使用HTTP和JSON或XML,因为它们是平台和语言无关的。 The HTTP API allows for a ReSTful architecture, which has proven to be a scalable model for developing distributed systems. HTTP API允许ReSTful架构,该架构已被证明是用于开发分布式系统的可扩展模型。

Historically, RPC-based approaches to distributed systems have shown a number of weak points: 从历史上看,基于RPC的分布式系统方法已经显示出许多弱点:

  • often they're language dependent. 通常他们是语言依赖的。 Thrift and Protobuf are more interoperable but they're still dependent on fairly specific 3rd party libraries. Thrift和Protobuf更具互操作性,但它们依赖于相当具体的第三方库。 In comparison, there are many implementations of HTTP clients and XML or JSON data bindings / processors. 相比之下,HTTP客户端和XML或JSON数据绑定/处理器有许多实现。

  • by tying together the client and server upgrades can become difficult - the client often must be upgraded at the same time as the server. 通过将客户端和服务器升级捆绑在一起可能变得困难 - 客户端通常必须与服务器同时升级。 In a truly distributed network this can be impossible. 在真正的分布式网络中,这是不可能的。

  • RPC is often not a great metaphor in a distributed system. RPC在分布式系统中通常不是一个很好的比喻。 By abstracting the network to an implementation concern they often encourage low-level 'chatty' interfaces which either involve too much network traffic or are not resilient to unreliable networks. 通过将网络抽象为实现问题,他们经常鼓励低级“聊天”接口,这些接口要么涉及过多的网络流量,要么对不可靠的网络不具有弹性。

  • binary transfer formats are more difficult to analyse / debug when something goes wrong. 当出现问题时,二进制传输格式更难分析/调试。

For these kinds of reasons people tend to choose Rest-with-HTTP-based APIs over proprietary RPC APIs. 出于这些原因,人们倾向于选择基于HTTP的Rest-over API而不是专有的RPC API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM