简体   繁体   English

微服务DDD CQRS

[英]Microservices DDD CQRS

I've been reading about DDD and microservices. 我一直在阅读有关DDD和微服务的信息。 Started to prototype by taking a use case for CQRS part. 通过使用CQRS部分的用例开始进行原型设计。 The use case is a sports soccer app which has videos, news, scores, and homepage. 该用例是一款运动足球应用程序,其中包含视频,新闻,乐谱和主页。 In this, I've identified the domains and Bounded context which are 在此,我确定了域和有界上下文

  1. News 新闻

  2. Videos 影片

  3. Scores 比分

  4. Homepage 主页

First, 3 domains are totally independent of each other. 首先,3个域完全相互独立。

Now, homepage domain requirements. 现在,主页域要求。 1. Score section 2. Videos section 3. Content section 1.得分部分2.视频部分3.内容部分

Content Section: It has its own database 内容部分:它有自己的数据库

Videos section: It will make HTTP call video service and get the data 视频部分:它将使HTTP调用视频服务并获取数据

Score section: It will make HTTP call Score service and get the data 评分部分:它将使HTTP调用评分服务并获取数据

My question is with homepage domain. 我的问题是首页域名。 I find it is highly coupled with other services and it's not independent. 我发现它与其他服务高度结合,并且不是独立的。

How can I design homepage domain? 如何设计主页域?

I find it is highly coupled with other services and it's not independent. 我发现它与其他服务高度结合,并且不是独立的。

Yes. 是。

You can improve the independence by thinking carefully about the failure modes; 您可以通过仔细考虑故障模式来提高独立性。 how should the UI elements behave when the relevant data authority is not available. 当相关数据权限不可用时,UI元素应如何表现。 You can, for example, have the homepage simply display a "data not available" message if the remote authority doesn't respond in a timely fashion. 例如,如果远程授权机构没有及时响应,则可以使主页仅显示“数据不可用”消息。 Or you can have the homepage display a cached copy of some stale data. 或者,您可以让主页显示一些过时数据的缓存副本。 It may even make sense to always render the response using cached data, with updates to the cache happening in the background. 始终使用缓存的数据来呈现响应甚至在后台进行缓存更新时,甚至可能是有意义的。

There are techniques that you can use to reduce the coupling between the services. 您可以使用一些技术来减少服务之间的耦合。
One approach is described by Udi Dahan, under the umbrella of UI Composition Techniques . Udi Dahan在UI合成技术的保护下描述了一种方法。 His idea is that you use an element, like a widget , to encapsulate the logic of display and the failure mode. 他的想法是,使用小部件之类的元素来封装显示逻辑和失败模式。

The underlying mechanics aren't really all that different; 底层的机制并没有真正的不同。 the widget has all of the same problems we had before when the data isn't available. 当数据不可用时,小部件会遇到我们以前遇到的所有相同问题。 But what it does do is separate out two problems (what do you do when the widget isn't available, what do you do when the data isn't available) that belong to different teams: the homepage team gets to decide what to do when the widget isn't available (perhaps a cached copy is used), the service team gets to decide what to do when the widget can't reach the backing data (perhaps the widget has its own cache of stale data). 但是它的作用是分离出属于不同团队的两个问题(当窗口小部件不可用时您将做什么,当数据不可用时您将做什么):首页团队可以决定要做什么当窗口小部件不可用(可能使用了缓存的副本)时,服务团队可以决定在窗口小部件无法到达后备数据(窗口小部件具有自己的过时数据缓存)时该怎么做。

There's no magic; 没有魔法; you've got a distributed system, and a consequence of this is that you need to consider in your design the fact that the remote processes won't always be available. 您拥有分布式系统,其结果是您需要在设计中考虑以下事实:远程进程并非总是可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM