当微服务体系结构中的CQRS模式导致整体数据结构时该怎么办
我正在尝试通过实施一个示例项目来学习微服务,试图选择一个半复杂的人,以面对微服务架构中的现实世界挑战。 这是我设计到这里的项目流的简化版本: flow 中所看到的那样
- 如您在图像 BFF )将从Frontend获得包含令牌
- bff 的请求,将通过将其发送给用户MS 的任命授权JWT令牌,
- 由公司ID,,公司IDS分开因此,在获得约会之前,我需要让用户公司
- Company ID将被发送到约会以获得公司的约会
- 约会将检查是否已授权演员要通过其角色获得约会清单(较早来自用户MS )
- 的约会列表
- 约会将返回约会内 请参阅在实体中,我确实具有双方的ID(Sidea,side)
- bff 将通过用户内部约会数据从ID中获取这些用户详细信息
- ,这些数据已返回, 客户的ID
- 有一个客户_id是公司MS 内部 在客户渴望访问的项目中,BFF将发送一个请求,以从项目MS 中获取该项目
- ,BFF将加入数据并将其返回到Frontend应用程序。
这也是微服务中实体的简化版本: 实体
现在,我正在使用构图API方法来获取我需要的数据,但是AS AS AS AS AS您可以看到流程很复杂,我想不出一种实施分页的方法,因为我可能需要对数据进行分类,过滤然后分页,因此我认为在这种情况下,这可能是一个好主意CQRS模式,但问题是因为我有许多这样的情况,所以我必须实施许多CQRS服务。
我想知道是否可以:
- 可以创建单个CQRS服务以将所有数据用于阅读目的而不是每种情况的CQRS?
- 对于这样的某些情况,CQRS读取数据库几乎与Monolith Architecture DB相同。是。这还好吗?
- 是否有其他方法可以探讨使用部分重复数据创建和管理多个CQRS的复杂性?
i'm trying to learn Microservices by implementing a sample project, tried to pick a semi-complex one to face real world challenges in Microservice architecture.
this is a simplified version of the project flow that I designed till here:
the flow
as you can see in the image I'm trying to get the list of appointments for a specific company, but since the required data is inside different Microservices, for getting the appointments I have to follow these steps:
- the API gateway (bff) will get the request from frontend that contains a token
- bff will authorize the jwt token by sending it to the users ms
- appointments are separated by companies ids, so before getting the appointments, I need to get the user company
- company id will be sent to appointments to get the appointments for the company
- appointments will check to see if actor is authorized to get the list of appointments by its role (came earlier from the user ms)
- appointments will return the list of appointments
- inside appointments as you can see in the entities, I do have the id of both sides (sideA, sideB)
- bff will get those users details by the ids from users
- inside appointments data that is returned, there is a customer_id that is the id of a customer inside the company ms so bff send another request to the company to get the customer details
- inside customer details, there is an id of a project that the customer is eager to visit so, bff will send a request to get the project from the projects ms
- at the end, bff will join the data and return it to the frontend application.
this is also the simplified version of entities inside Microservices:
entities
right now, i'm using composition API approach to get the data I need, but as you can see the flow is complicated, and I can't think of a way to implement pagination, since I might need to sort, filter and then paginate the data, so I think in this situation, this might be a good idea to use CQRS pattern, but the problem is since I have many situations like this, I have to implement lots of CQRS services.
I'm wondering if:
- is it possible to create a single CQRS service to have all the data for read purpose, instead of CQRS for each situation?
- for some situations like this, the CQRS read database will becomes almost identical to a monolith architecture db. is. this okay?!
- is there any alternative way to scape the complexity of creating and managing multiple CQRSs with partial repetitive data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CQR将帮助您在一次通话中获取所有必需的详细信息。 CQRS服务将有多个表,这些表是不同的微服务的一部分。
一个示例将是“订单ViewService”需要从“ OrderService”,“ evelyService”,“ counctingService”中收听和存储事件。但是,它不会听取“订单ViewService”不关心的其他多种服务。
因此,我在这里提出的观点是数据库不会变得与整体数据库如此相似,因为它将具有更多的详细信息。
对于您的项目,您可能需要一个可以满足您要求的单个CQR。
似乎您的要求依赖于所有微服务,因此单个CQRS服务可以帮助您解决要求。
另外,如果您担心空间,请确保仅将哪些详细信息保存到视图/读取CQRS数据库。从而确保我们不会为所有服务的所有详细信息压倒DB。
随着应用程序的增长,可以有多个CQRS服务收听不同的服务或服务组合,从而服务其职责。
参考 - https://microservices.io/patterns/patterns/data/data/data/cqrs.html
i认为这是解释的,这是我对CQR的想法。让我知道您是否有任何疑问,将其作为评论发布。
CQRS will help you get all the required details in one call. A CQRS service will have multiple tables that are part of different microservices.
An example will be like "OrderViewService" will require to listen and store events from "OrderService", "DeliveryService", "AccountingService". But it wont be listening to multiple other services which are not of concern for "OrderViewService".
So the point I am making here is the database won't become so similar to the monolithic database as it would have a lot more details.
For your project you might require a single CQRS that may deliver your requirements.
As it seems your requirements have dependency on all of the microservices and so a single CQRS service could help you solve the requirements.
Also if you are concerned about the space make sure what details would be required were only be saved to the view/read CQRS database. Thereby ensuring that we are not overwhelming the db with all the details from all the services.
As application grows there can be multiple CQRS services listening to different services or a combination of services and thereby serving their responsibilities.
Reference - https://microservices.io/patterns/data/cqrs.html
I think this explains and these are my thoughts about CQRS. Let me know if you have any questions post it as comments.