Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用 Node.js 搭建一个 API 网关 #2042

Merged
merged 4 commits into from
Aug 15, 2017
Merged

Conversation

MuYunyun
Copy link
Contributor

@MuYunyun MuYunyun commented Aug 10, 2017

resolve #2006

@jasonxia23
Copy link

认领校对~@sqrthree

@linhe0x0
Copy link
Member

@jasonxia23 好的呢 🍺

@CACppuccino
Copy link
Contributor

@sqrthree 校对认领

@linhe0x0
Copy link
Member

@CACppuccino 妥妥哒 🍻

Copy link
Contributor

@CACppuccino CACppuccino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

总体上无问题,个别格式需要改正


Microservices are a service oriented architecture where teams can design, develop and ship their applications independently. It allows **technology diversity** on various levels of the system, where teams can benefit from using the best language, database, protocol, and transportation layer for the given technical challenge. For example, one team can use JSON over HTTP REST while the other team can use gRPC over HTTP/2 or a messaging broker like RabbitMQ.
微服务是面向服务的架构,团队可以独立设计,开发和发布应用程序。它允许在系统各个层面上的**技术多样性**,团队可以在技术挑战中使用最佳语言,数据库,协议和传输层,从而受益。例如,一个团队可以使用 JSON over HTTP REST,而另一个团队可以使用 HTTP/2 上的 gRPC 或 RabbitMQ 等消息传递代理。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON over HTTP REST => HTTP REST 上的 JSON


Using different data serialization and protocols can be powerful in certain situations, but **clients** that want to consume our product may **have different requirements**. The problem can also occur in systems with homogeneous technology stack as consumers can vary from a desktop browser through mobile devices and gaming consoles to legacy systems. One client may expect XML format while the other one wants JSON. In many cases, you need to support both.
在某些情况下使用不同的数据序列化和协议可能是强大的,但**要使用我们的产品的**客户**可能有不同的需求**。该问题也可能发生在具有同质技术栈的系统中,因为客户可以从桌面浏览器通过移动设备和游戏机到遗留系统。一个客户可能期望XML格式,而另一个客户可能希望JSON。在许多情况下,您需要同时支持它们。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一个客户可能期望XML格式 => 一个客户可能期望 XML 格式

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON 空格


As API Gateway provides functionality for client applications like browsers - it can be implemented and managed by the team who is responsible for the frontend application.
由于 API Gateway 为客户端应用程序(如浏览器)提供了功能,它可以由负责开发前端应用程序的团队实施和管理。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API GATEWAY应该统一翻译为 API 网关,不再使用gateway


![](https://image.slidesharecdn.com/qconpaved-170718200756/95/paved-paas-to-microservices-7-638.jpg?cb=1500408507)*Netflix's approach to handle different clients, [source](https://www.slideshare.net/yunongx/paved-paas-to-microservices)*
![](https://image.slidesharecdn.com/qconpaved-170718200756/95/paved-paas-to-microservices-7-638.jpg?cb=1500408507) **Netflix处理不同客户端的方法 , [资源](https://www.slideshare.net/yunongx/paved-paas-to-microservices)**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

中英文空格

@CACppuccino
Copy link
Contributor

@MuYunyun @sqrthree 校对完毕

Copy link

@jasonxia23 jasonxia23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

译者文笔超好~校正完毕
@sqrthree @MuYunyun


Microservices are a service oriented architecture where teams can design, develop and ship their applications independently. It allows **technology diversity** on various levels of the system, where teams can benefit from using the best language, database, protocol, and transportation layer for the given technical challenge. For example, one team can use JSON over HTTP REST while the other team can use gRPC over HTTP/2 or a messaging broker like RabbitMQ.
微服务是面向服务的架构,团队可以独立设计,开发和发布应用程序。它允许在系统各个层面上的**技术多样性**,团队可以在技术挑战中使用最佳语言,数据库,协议和传输层,从而受益。例如,一个团队可以使用 JSON over HTTP REST,而另一个团队可以使用 HTTP/2 上的 gRPC 或 RabbitMQ 等消息传递代理。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

团队可以独立设计,开发和发布应用程序
=>
团队可以独立设计、开发和发布应用程序


Microservices are a service oriented architecture where teams can design, develop and ship their applications independently. It allows **technology diversity** on various levels of the system, where teams can benefit from using the best language, database, protocol, and transportation layer for the given technical challenge. For example, one team can use JSON over HTTP REST while the other team can use gRPC over HTTP/2 or a messaging broker like RabbitMQ.
微服务是面向服务的架构,团队可以独立设计,开发和发布应用程序。它允许在系统各个层面上的**技术多样性**,团队可以在技术挑战中使用最佳语言,数据库,协议和传输层,从而受益。例如,一个团队可以使用 JSON over HTTP REST,而另一个团队可以使用 HTTP/2 上的 gRPC 或 RabbitMQ 等消息传递代理。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在技术挑战中使用最佳语言,数据库,协议和传输层
=>
在给定的技术难题中使用最佳语言、数据库、协议和传输层

  1. 最好用顿号;
  2. challenge 可以理解为难题。


Microservices are a service oriented architecture where teams can design, develop and ship their applications independently. It allows **technology diversity** on various levels of the system, where teams can benefit from using the best language, database, protocol, and transportation layer for the given technical challenge. For example, one team can use JSON over HTTP REST while the other team can use gRPC over HTTP/2 or a messaging broker like RabbitMQ.
微服务是面向服务的架构,团队可以独立设计,开发和发布应用程序。它允许在系统各个层面上的**技术多样性**,团队可以在技术挑战中使用最佳语言,数据库,协议和传输层,从而受益。例如,一个团队可以使用 JSON over HTTP REST,而另一个团队可以使用 HTTP/2 上的 gRPC 或 RabbitMQ 等消息传递代理。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON over HTTP REST
=>
基于 HTTP REST 的 JSON
使用 HTTP/2 上的
=>
使用基于 HTTP/2 的
保持一致,似乎也更通顺


Microservices are a service oriented architecture where teams can design, develop and ship their applications independently. It allows **technology diversity** on various levels of the system, where teams can benefit from using the best language, database, protocol, and transportation layer for the given technical challenge. For example, one team can use JSON over HTTP REST while the other team can use gRPC over HTTP/2 or a messaging broker like RabbitMQ.
微服务是面向服务的架构,团队可以独立设计,开发和发布应用程序。它允许在系统各个层面上的**技术多样性**,团队可以在技术挑战中使用最佳语言,数据库,协议和传输层,从而受益。例如,一个团队可以使用 JSON over HTTP REST,而另一个团队可以使用 HTTP/2 上的 gRPC 或 RabbitMQ 等消息传递代理。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

消息传递代理
=>
消息代理
https://zh.wikipedia.org/wiki/RabbitMQ


Services in a microservices architecture share some common requirements regarding authentication and transportation when they need to be accessible by external clients. API Gateway s provide a **shared layer** to handle differences between service protocols and fulfills the requirements of specific clients like desktop browsers, mobile devices, and legacy systems.
外部客户端访问微服务架构中的服务时,服务端会对认证和传输有一些常见的要求。API 网关提供**共享层**来处理服务协议之间的差异,并满足特定客户端(如桌面浏览器,移动设备和旧系统)的要求。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

旧系统
=>
遗留系统

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个地方感觉还是用老系统比较接近日常用语


To summarize: we don't want to implement our internal services in our microservices architecture in a way to support multiple clients and re-implement the same logic all over. This is where the **API Gateway** comes into the picture and provides a **shared layer** to handle differences between service protocols and fulfills the requirements of specific clients.
总结:我们不想在我们的微服务架构中实现我们的内部服务,以支持多个客户端并可以重复使用相同的逻辑。这就是**API网关**出现的原因,其作为**共享层**来处理服务协议之间的差异并满足特定客户端的要求。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API网关
=>
API 网关


API Gateway is a type of service in a microservices architecture which provides a shared layer and API for clients to communicate with internal services. The API Gateway can **route requests**, transform protocols, **aggregate data** and **implement shared logic** like authentication and rate-limiters.
API 网关是微服务架构中的一种服务,它为客户端提供共享层和 API ,以便与内部服务进行通信。API 网关可以进行**路由请求**,转换协议,**聚合数据**以及**实现共享逻辑**,如认证和速率限制器。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API ,
=>
API,


Netflix successfully uses Node.js API Gateways with their Java backend to support a broad range of clients - to learn more about their approach read [The "Paved Road" PaaS for Microservices at Netflix](https://www.infoq.com/news/2017/06/paved-paas-netflix) article.
Netflix 成功地使用 Node.js API 网关及其 Java 后端来支持广泛的客户端 - 了解更多关于它们的方法阅读 [The "Paved Road" PaaS for Microservices at Netflix](https://www.infoq.com/news/2017/06/paved-paas-netflix) 这篇文章

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

链接翻译出来是否更好~


# Node.js API Gateways
# Node.js API网关

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

空格~


While you want to do simple things in your API Gateway like routing requests to specific services you can **use a reverse proxy** like nginx. But at some point, you may need to implement logic that's not supported in general proxies. In this case, you can **implement your own** API Gateway in Node.js.
当您希望在 API 网关中执行简单的操作,比如将请求路由到特定服务,您可以使用像 nginx 这样的**反向代理**。但在某些时候,您可能需要实现一般代理不支持的逻辑。在这种情况下,您可以在 Node.js 中**实现自己的**API网关。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

空格~

@linhe0x0
Copy link
Member

linhe0x0 commented Aug 11, 2017

@MuYunyun 两位校对者都已经校对好了~ 可以来根据校对意见进行调整了哈 ┏ (゜ω゜)=☞

@MuYunyun
Copy link
Contributor Author

@sqrthree 修改完毕


API Gateway is a type of service in a microservices architecture which provides a shared layer and API for clients to communicate with internal services. The API Gateway can **route requests**, transform protocols, **aggregate data** and **implement shared logic** like authentication and rate-limiters.
API 网关是微服务架构中的一种服务,它为客户端提供共享层和 API,以便与内部服务进行通信。API 网关可以进行**路由请求**,转换协议,**聚合数据**以及**实现共享逻辑**,如认证和速率限制器。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

『进行路由请求,转换协议,聚合数据以及实现共享逻辑』=>『进行路由请求、转换协议、聚合数据以及实现共享逻辑


Our system can have one or multiple API Gateways, depending on the clients' requirements. For example, we can have a separate gateway for desktop browsers, mobile applications and public API(s) as well.
我们的系统可以有一个或多个 API 网关,具体取决于客户的需求。例如,我们可以为桌面浏览器,移动应用程序和公共 API 提供单独的网关。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

『桌面浏览器』后面应使用顿号。


![API Gateway](https://blog-assets.risingstack.com/2017/07/api-gateway-1.png)*API Gateway as an entry point to microservices*
![API Gateway](https://blog-assets.risingstack.com/2017/07/api-gateway-1.png)**API 网关作为微服务的切入点**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

图片和文字之间加一个空行吧。


Netflix successfully uses Node.js API Gateways with their Java backend to support a broad range of clients - to learn more about their approach read [The "Paved Road" PaaS for Microservices at Netflix](https://www.infoq.com/news/2017/06/paved-paas-netflix) article.
Netflix 成功地使用 Node.js API 网关及其 Java 后端来支持广泛的客户端 - 了解更多关于它们的方法阅读 [The "Paved Road" PaaS for Microservices at Netflix](https://www.infoq.com/news/2017/06/paved-paas-netflix) 这篇文章
![](https://image.slidesharecdn.com/qconpaved-170718200756/95/paved-paas-to-microservices-7-638.jpg?cb=1500408507) **Netflix 处理不同客户端的方法, [资源](https://www.slideshare.net/yunongx/paved-paas-to-microservices)**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同样需要一个空行。

@MuYunyun
Copy link
Contributor Author

@sqrthree 修改完毕

@MuYunyun
Copy link
Contributor Author

@sqrthree 这篇文章,我在segmentfault看到同文翻译了,好坑啊,这还能获取到积分吗?

@linhe0x0 linhe0x0 merged commit 5a4b152 into xitu:master Aug 15, 2017
@linhe0x0
Copy link
Member

没事,冲突常有。已经 merge 啦~ 快快麻溜发布到掘金专栏然后给我发下链接,方便及时添加积分哟。

@MuYunyun
Copy link
Contributor Author

@sqrthree 已发到掘金,掘金链接

@MuYunyun MuYunyun deleted the translate branch August 25, 2017 03:51
cdadar pushed a commit to cdadar/gold-miner that referenced this pull request Dec 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

使用 Node.js 搭建一个 API 网关
4 participants