在Nestjs中缩放基于兔子的微服务

发布于 2025-02-01 14:27:47 字数 672 浏览 0 评论 0原文

我需要在Nestjs中创建一个基于RabbitMQ的微服务解决方案。为了扩展系统,我需要部署同一微服务(服务器)的几个实例(例如,3个码头)收听相同的RabbitMQ主题,处理来自消费者(客户端)的处理请求(请参见下图)。我假设这三个实例使用一种循环的罗宾来弹出来自队列/主题的消息/请求并处理它们,然后将结果返回另一个队列(即'charback'queue)中的结果。我想知道

  1. Nestjs是否已经处理了相关性_id(将响应与请求|解决问题相关联,在该排队中收到响应后,尚不清楚该响应属于哪个请求。)当前图书馆?
  2. NESTJS是否会创建独家回调队列(部署了相同微服务的几个实例),或者我需要在我的代码中自己照顾它(即工人(aka:server | server | microservice)正在等待该排队的请求出现请求时,它可以使用Reply_to field的队列将结果发送给客户/消费者。换句话说,客户(消费者)等待回调队列上的数据。出现消息时,它会检查Correlation_ID属性。如果它与请求的值匹配,则将返回到应用程序的响应。

I need to create a RabbitMQ-based microservices solution in Nestjs. To scale the system, I need to deploy several instances (e.g., 3 dockers) of the same microservice (server) listening to the same RabbitMQ topic, processing requests coming from the consumer (client) (see the following figure). I assume these 3 instances use a kind of Round Robin to pop up messages/requests from the queue/topic and process them and then return the results in another queue (i.e., 'callback' queue) to the consumer. I am wondering if

  1. Nestjs already handles the correlation_id (to correlate responses with requests | to tackle the issue, having received a response in that queue it's not clear to which request the response belongs.) under the hood, or do I need to extend the current library?
  2. Does NestJs create an exclusive callback queue (when several instances of the same microservices are deployed) or do I need to take care of that myself in my code (i.e., The worker (aka: server | microservice) is waiting for requests on that queue. When a request appears, it does the job and sends a message with the result back to the Client/Consumer, using the queue from the reply_to field.). In other words, The client (consumer) waits for data on the callback queue. When a message appears, it checks the correlation_id property. If it matches the value from the request it returns the response to the application.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文