什么是API gateway
- 确保客户端无法察觉应用程序是如何被拆分为多项微服务的。
- 确保客户端不受服务实例的位置的影响。
- 为每套客户端提供最优API。
- 降低请求/往返次数。举例来说,API网关能够确保客户端在单次往返中就从多项服务中检索出数据。请求数量更少意味着运行负担更低且用户体验更好。API网关对于移动应用而言是必不可少的。
- 将从客户端调用多项服务的逻辑转换为从API网关处调用,从而简化整个客户端
实现方式
1. nginx-upsync-module
该模块可以使nginx动态同步service 配置,无需重启生效。可以配合着consul或者etcd一起使用
下面的例子就是使用的consul。
nginx-upsync-module - Nginx C module, sync upstreams from consul or others, dynamically modify backend-servers attribute(weight, max_fails,...), needn't reload nginx.
It may not always be convenient to modify configuration files and restart NGINX. For example, if you are experiencing large amounts of traffic and high load, restarting NGINX and reloading