简体   繁体   English

基于Akka集群的微服务API网关模式实现

[英]API Gateway pattern implementation for microservices based on Akka cluster

I try create some microservices based on Akka which use CQRS. 我尝试基于Akka创建一些使用CQRS的微服务。 So my microservice has write (send command to cluster) and read side (read projections from database) with Http endpoints, but this is not the main problem. 因此,我的微服务具有Http端点的写(发送命令到集群)和读侧(从数据库读取投影),但这不是主要问题。 Because of many microservices, the question arose as to collect complex API for clients. 由于存在许多微服务,因此出现了为客户收集复杂API的问题。 I found answer: API Gateway pattern. 我找到答案:API网关模式。 But I have next question: How can I implement it? 但是,我还有一个问题:如何实施?

  1. I can create separate project, which will implement API Gateway pattern (in simple case it is a reverse proxy). 我可以创建一个单独的项目,该项目将实现API网关模式(在简单情况下,它是一个反向代理)。 Full stack will be: 全栈将是:

     Load balancer -> API Gateway project -> Load balancer -> Microcervice read part -> Database -> Microcervice write part -> Akka cluster 

Pros: 优点:

API Gateway separate project with own abstractions API Gateway具有自己抽象的独立项目

Cons: 缺点:

Two balancers, and not so fast proxy in API Gateway project 两个平衡器,API Gateway项目中的代理不是那么快

  1. API Gateway (auth, etc) implemented in Microservice parts, load balancer will collect endpoints in complex API. 在微服务部件中实现的API网关(身份验证等),负载均衡器将收集复杂API中的端点。 Full stack will be: 全栈将是:

     Load balancer -> Microcervice read part (with public API) -> Database -> Microcervice write part (with public API) -> Akka cluster 

Pros: 优点:

  1. Direct access to cluster and databases 直接访问集群和数据库
  2. Fast response 反应快

Cons: 缺点:

Complex microservices parts, blending layers 复杂的微服务零件,混合层

What variant is more preferable or is another best? 哪种变体更可取,还是另一种更好?

Checkout the Kong project, which has a nice diagram on their github page showing how you want to think about an API gateway. 签出Kong项目,在其github页面上有一个漂亮的图表,显示了您如何考虑API网关。 Also you may want to consider using them for your implementation. 另外,您可能需要考虑在实现中使用它们。

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

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