# 介绍

顾名思义，是出现在系统边界上的一个面向API的、串行集中式的强管控服务，这里的边界是企业IT系统的边界，主要起到隔离外部访问与内部系统的作用。

参考资料

[浅谈微服务架构下的API网关](https://www.jianshu.com/p/633363cf3a7e)

[统一开发框架——API网关构建微服务](http://www.360doc.com/content/18/0826/14/99071_781332992.shtml)

[谈谈微服务中的 API 网关（API Gateway）](https://www.cnblogs.com/savorboard/p/api-gateway.html)

## 单节点场景

![](/files/-LfnTHNTG8ZnSfkFhnGY)

## 多节点场景

![](/files/-LfnTHNV6XMGTEfFUkGG)

## 网关作用

* 统一入口
* 安全：黑名单、权限身份认证
* 限流：实现微服务访问流量计算，基于流量计算分析进行限流，可以定义多种限流规则。
* 缓存：数据缓存
* 日志：日志记录
* 监控：记录请求响应数据，api耗时分析，性能监控
* 重试：异常重试
* 熔断： 降级

## 现有框架

* [Tyk](https://tyk.io/)：Tyk是一个开放源码的API网关，它是快速、可扩展和现代的。Tyk提供了一个API管理平台，其中包括API网关、API分析、开发人员门户和API管理面板。Trk是一个基于Go实现的网关服务。
* [Kong](https://getkong.org/about/)：Kong是一个可扩展的开放源码API Layer(也称为API网关或API中间件)。Kong在任何RESTfulAPI的前面运行，通过插件扩展，它提供了超越核心平台的额外功能和服务。
* [Orange](http://orange.sumory.com/)：和Kong类似也是基于OpenResty的一个API网关程序，是由国人开发的。
* [Netflix](https://github.com/Netflix/zuul)[zuul](https://github.com/Netflix/zuul)：Zuul是一种提供动态路由、监视、弹性、安全性等功能的边缘服务。Zuul是Netflix出品的一个基于JVM路由和服务端的负载均衡器。
* [apiaxle](http://apiaxle.com/):Nodejs实现的一个API网关。
* [api](https://apiumbrella.io/)[-umbrella](https://apiumbrella.io/): Ruby实现的一个API网关。

## 技术选型

目前流行两层两者相结合的网关

* Zuul
  * 重试、熔断
  * 业务，微服务，用户权限验证，微服务之间鉴权
* Nginx+lua (kong,orange)
  * 做一些限流
  * 用户权限验证
  * 不涉及业务，公用的网关功能

![](/files/-Lfy8GWGwEHB2Q0wgQgi)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://openresty.shujuwajue.com/master.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
