API 网关和微服务通信 [英] API gateway and microservices communication

查看:32
本文介绍了API 网关和微服务通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建微服务架构,我需要交流方面的帮助.API 网关与服务通信的最佳方法是什么?我的 API 网关将是 graphql apollo 服务器,服务将是 REST API. 我应该使用 REST 与服务或某些消息系统(如 RabbitMQ )通信吗?

I am building microservices arhitecture and i need help with communication. What is best approach for API gateway to communicate with services ? My API gateway will be graphql apollo server and services will be REST APIs. Should i use REST to communicate with services or some message system like RabbitMQ ?

推荐答案

您可以同时使用两种方式,但使用像 RabbitMQ 这样的消息代理系统会给您带来负载平衡的优势.对于 HTTP 休息通信,您需要一个负载平衡器,以便将流量分配并路由到各种实例.但是对于像 RabbitMQ 这样的消息代理,代理本身就是负载均衡器.如果多个消费者同时侦听相同的地址,消息将并行传递,而不是像 HTTP 的行为那样相互阻塞.我希望我能解释清楚:)

You can do it both ways but using a message broker system like RabbitMQ will give you the advantage of load balancing. With HTTP rest communication, you need a load balancer so that traffic is distributed and routed to the various instances. But with a message broker like RabbitMQ, broker itself is the load balancer. If multiple consumers are listening same address at the same time messages will be delivered parallel instead of blocking each other as the behavior of HTTP. I hope I could explain it clearly :)

您可以查看这篇文章,其中解释了这些优势.

You can look at this article which explains the advantages.

这篇关于API 网关和微服务通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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