API网关应该通过队列还是直接与其他μService通信? [英] Should an API Gateway Communicate via a Queue or directly to other μServices?
问题描述
我想知道我的两种方法中哪一种更合适,还是有另一种方法?
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
-
UI
将HTTP
请求发送到GATEWAY
-
GATEWAY
向μSERVICE A
发送 -
μSERVICE A
返回SUCCESS
或ERROR
- 事件存储在
EVENT STORE
中并发布到QUEUE
-
PROJECTION DATABASE
已更新 - 其他
μSERVICES
可能消耗事件
HTTP
请求
UI
sendsHTTP
request toGATEWAY
GATEWAY
sendsHTTP
request toμSERVICE A
μSERVICE A
returns eitherSUCCESS
orERROR
- Event is stored in
EVENT STORE
and published toQUEUE
PROJECTION DATABASE
is updated- Other
μSERVICES
might consume event
(2)事件
通过消息队列进行基于事件的通信
(2) Events
Event-based communication via a message queue
-
UI
将HTTP
请求发送到GATEWAY
-
GATEWAY
将事件发布到QUEUE
-
μSERVICE A
使用事件 - 事件存储在
EVENT STORE
中并发布到QUEUE
-
PROJECTION DATABASE
已更新 - 其他
μSERVICES
可能消耗事件 -
GATEWAY
使用事件并将响应(SUCCESS
或ERROR
)发送到UI
UI
sendsHTTP
request toGATEWAY
GATEWAY
published event toQUEUE
μSERVICE A
consumes event- Event is stored in
EVENT STORE
and published toQUEUE
PROJECTION DATABASE
is updated- Other
μSERVICES
might consume event GATEWAY
consumes event and sends response (SUCCESS
orERROR
) toUI
如果我误解了一些概念,我真的很抱歉,我对这种建筑风格还比较陌生.
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屋!