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

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

问题描述

我正在构建微服务架构,我需要沟通方面的帮助.API网关与服务进行通信的最佳方法是什么?我的API网关将是 graphql apollo 服务器,服务将是 REST APIs .我应该使用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 rest通信,您需要一个负载平衡器,以便将流量分配并路由到各个实例.但是对于像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天全站免登陆