API网关应该通过队列还是直接与其他μService通信? [英] Should an API Gateway Communicate via a Queue or directly to other μServices?

查看:119
本文介绍了API网关应该通过队列还是直接与其他μService通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我的两种方法中哪一种更合适,还是有另一种方法?

I was wondering which of my two methods is more appropriate, or is there event another one?

GATEWAYμSERVICE A

Direct communication between GATEWAY and μSERVICE A

  1. UIHTTP请求发送到GATEWAY
  2. GATEWAYμSERVICE A
  3. 发送HTTP请求
  4. μSERVICE A返回SUCCESSERROR
  5. 事件存储在EVENT STORE中并发布到QUEUE
  6. PROJECTION DATABASE已更新
  7. 其他μSERVICES可能消耗事件
  1. UI sends HTTP request to GATEWAY
  2. GATEWAY sends HTTP request to μSERVICE A
  3. μSERVICE A returns either SUCCESS or ERROR
  4. Event is stored in EVENT STORE and published to QUEUE
  5. PROJECTION DATABASE is updated
  6. Other μSERVICES might consume event


(2)事件

通过消息队列进行基于事件的通信


(2) Events

Event-based communication via a message queue

  1. UIHTTP请求发送到GATEWAY
  2. GATEWAY将事件发布到QUEUE
  3. μSERVICE A使用事件
  4. 事件存储在EVENT STORE中并发布到QUEUE
  5. PROJECTION DATABASE已更新
  6. 其他μSERVICES可能消耗事件
  7. GATEWAY使用事件并将响应(SUCCESSERROR)发送到UI
  1. UI sends HTTP request to GATEWAY
  2. GATEWAY published event to QUEUE
  3. μSERVICE A consumes event
  4. Event is stored in EVENT STORE and published to QUEUE
  5. PROJECTION DATABASE is updated
  6. Other μSERVICES might consume event
  7. GATEWAY consumes event and sends response (SUCCESS or ERROR) to UI


如果我误解了一些概念,我真的很抱歉,我对这种建筑风格还比较陌生.


I am really sorry if I misunderstood some concept, I am relatively new to this style of architecture.

在此先感谢您的帮助! :)

Thanks in advance for every help! :)

推荐答案

第二种方法是首选方法,并且是异步方法.

Second approach is a preferred way and is async approach.

直接

第一种方法是您的microsvc B和C等待事件被发布.该系统的可伸缩性直接取决于microsvcA.如果microsvc A出现故障或落后于将事件写入队列怎么办?就像单点故障和瓶颈一样.您无法轻松扩展系统.

In first approach your microsvc B and C wait for the event to get published . The scalability of this system is directly dependent on microsvc A. what if microsvc A is down or falling behind writing events to queue? it's like single point of failure and bottleneck. you can't scale system easily.

事件

在微服务中,我们保持系统异步,以便它们可以扩展. 网关应该使用pub/sub将其写入队列,并且所有这些微服务都可以同时使用事件.整个系统更加健壮,并且可以扩展.

In microservices we keep system async so they can scale. Gateway should be writing to the queue using pub/sub and all these microservices can use events at same time. system over all is more robust and can be scaled.

这篇关于API网关应该通过队列还是直接与其他μService通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆