2

我想问一下 Consul 和 API Gateway 的功能。Consul 可以替代 API Gateway 作为服务引用者吗?

或者如何在微服务架构方面同时使用它们?

谢谢你

4

2 回答 2

2

Consul is multi datacenter service discovery (+health checking) and distributed K/V store.

API Gateway is a service that handles all the tasks involved in accepting and processing API calls, including traffic management, authorization and access control, monitoring, and API version management.

so they're quite different..

depends on what you're trying to achieve and your current API Gateway use case, you may be able to use Consul + Consul aware load balancers, such as https://github.com/fabiolb/fabio and https://traefik.io/.

于 2017-12-16T21:19:43.320 回答
2

在高层次上,API 网关将成为您的微服务的单一入口点。它将允许您为您的客户提供一致的用户体验 - 无论后端服务如何。

它们充当一种抽象——当你到达一个/product/{productId}端点时,你不需要知道内部微服务,例如/reviews/recommendations等等——网关可以为你做这件事并返回一个单一的响应。

API 网关将被配置为在侦听路径上接收请求,例如

curl http://gateway.com/myservice/mypath -H 'Authorization: secret_auth_token'

在内部,网关将接收请求,并将看到该请求myservice指向特定的 api 定义。

并且基于该身份验证令牌,将能够确定是否允许用户访问、什么速率限制/配额以及允许他们访问的上游目标和路径。几个典型特征:

  • 认证与授权
  • 速率限制
  • 主体变换(过滤器/映射缩减/Json -> XML,XML -> Json)
  • 标头注入
  • Json 模式验证
  • 方法转换
  • 模拟回应
  • API 版本控制策略
  • 向多个目标发送请求
  • 名单还在继续。

因此,网关随后会将请求代理到myservice.com/mypath例如并将响应返回给客户端。

现在让我们假设您希望您的上游具有高可用性 - 例如,您可能拥有myservice1.commyservice2.com.

网关可以配置为在这些服务之间对请求进行负载平衡。您可以使用网关的功能来测试上游的健康状况,但也有专门的工具。Consul 就是这样一种工具。

API 网关应该能够与服务发现工具集成。因此,让我们假设myservice1.com因维护而停机,网关将知道永远不会在那里发送流量,并且只会发送service2.com到 service1 恢复。

下面的屏幕截图是对 Consul 的 tyk.io api 网关集成支持的示例。

在此处输入图像描述

于 2018-06-20T12:49:32.850 回答