从多个微服务查询数据

发布于 2025-02-02 18:43:53 字数 907 浏览 2 评论 0 原文

我正在尝试设计一个使用微服务体系结构的应用程序。该服务将具有API网关,用户服务,然后为每个分析源提供单独的服务。

例如,可以说我有Twitter分析数据和Instagram分析数据。 Twitter分析数据和Instagram分析数据将有一个分开的微服务。这些微服务将处理该服务的OAuth,存储数据并提取数据。我的问题是:我如何从一个服务请求数据,可以说用户服务,然后基于用户服务的数据,向Instagram服务和Twitter服务请求以向该用户请求分析信息。

但是,如果我需要 n 我需要要求的服务量会发生什么?就像说用户需要Facebook,Instagram,Twitter和Tiktok的分析数据。我如何处理向每个人提出单独的请求,然后将其合并为对客户的单个响应?

我正在考虑使用API​​网关,因为我读到您可以支持多个微服务的请求。我完全确定该怎么做,但是我发现 AWS的这篇文章概述了不同的策略。

我还阅读了这个问题 >“您应该在服务中实现端点以促进这两个请求。如果您提出了n请求,则做错了”。,现在我什至不确定我是否在正确追踪。

我以正确的方式接近这一点吗?

I'm trying to design an application that uses the microservices architecture. The service would have an api gateway, a user service and then a seperate service for each analytic source.

For example, lets say I had twitter analytics data and instagram analytics data. There would be a seperate microservice for twitter analytics data and instagram analytics data. These microservices would handle oauth for that service, storing data and pulling data. My question is this: how would I request data from one service, lets say the user service, and then based on data from the user service, make a request to the instagram service and twitter service to request analytics info for that user.

However what would happen if I had n amount of services that I needed to request to? Like let's say a user needs analytics data from facebook, instagram, twitter and tiktok. How would I handle making a seperate request to each and then combine into a single response for the client?

I was thinking of using an api gateway as I've read that you can support request fanning-out to multiple microservices. I'm exactly sure how to do that however I found this article from aws outlining the different strategies.

I've also read over this question that says "You should implement endpoints in the services to facilitate these two requests. If you're making n requests, you've done it wrong". So now I'm not even sure if I'm on the right track.

Am I approaching this the correct way?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜是你 2025-02-09 18:43:53

我认为解决上述问题的解决方案将是CQRS设计模式的使用。

这个想法将是一项单一的服务,它会在Twitter Analytics和Instagram Analytics中听这些事件,并将这些详细信息保存在数据库中。存储数据后,我们可以点击此服务以获取所需的数据。

最终,我们正在介绍中间服务,该服务将在这些分析服务中聆听事件并将其保存到数据库中。现在,我们可以通过对此特定服务进行单个API调用来避免多个API调用,这将为您提供所需的详细信息。

我认为这可能会有所帮助!!

参考: https://microservices.io/patterns/data/data/cqrs.html#:~: text = xtt = xtt = xt = how%20to; %20回路%20DATA,已发布%20by%20 the%维修%20that%20 own%20 the%20Data

I think the solution to the above problem will be the usage of CQRS design pattern.

The idea will be a single service that listens to the events in Twitter analytics and Instagram analytics and save those details in a database. Once the data is stored we can hit this service to get the required data.

Eventually we are introducing an intermediatory service which will listen to the events in those analytics services and save them to a database. Now we can avoid multiple api calls by making a single api call to this particular service which will give you the required details.

I think this might be of some help !!.

References : https://microservices.io/patterns/data/cqrs.html#:~:text=How%20to%20implement%20a%20query%20that%20retrieves%20data,published%20by%20the%20service%20that%20own%20the%20data.
https://medium.com/design-microservices-architecture-with-patterns/cqrs-design-pattern-in-microservices-architectures-5d41e359768c

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文