如何使用域驱动设计为需求建模 [英] How to model the requirement using domain driven design
问题描述
我有一个要求,我需要根据某些条件将两个事件分组为一个事务。以下是对该要求的一些思考。
I have a requirement where i need to group the two events as one transaction by grouping them on certain criteria. Below is the some thoughts on the requirement.
事件::
- 我们将持续接收事件到我们的系统。
- 每个事件都有一些缓冲时间可以与其他事件分组。
- 如果经过了缓冲时间,则需要丢弃该事件。
- 我们需要根据两个事件信息将两个事件分组。
- 如果事件信息不足,则我们会将事件信息发送到其他组件,该组件将以更正后的数据做出响应。
- 每当我们对事件进行一些分组时即使相关事件没有100%确定匹配标准,但如果相关事件进入了数据校正组件,我们希望保留另一个事件。之所以要执行此步骤,是因为我们想尽可能地匹配事件。
- We will receive events continuously to our systems.
- Each event will have some buffer time to group with other event.
- If buffer time elapses then we need to discard the event.
- We need to group the two events into one group depending on the two events information.
- If event information is not sufficient then we will send event info to other component which will response with corrected data.
- Whenever we grouping the events some times we want to hold the other event if related event went to data correcting component even though we are not 100% sure about the matching criteria. This step we want to perform because we want to match the events as many as possible.
我想使用域驱动来建模此需求设计任何建议将不胜感激。
I want to model this requirement using domain driven design any suggestions will be appreciated.
推荐答案
在不知道您的业务需求的情况下,很难回答。但是我们可以先从假设和定义开始:
Without knowing your business requirements, it's kind of hard to answer. But we can start with assumptions and definitions first:
我将DDD中的事件称为对您的域而言很重要的事情(在过去)
I refer to an event in DDD as something that is important for your domain, has happened (in the past), is a undeniable fact and cannot be undone.
在我的定义中,聚合或域服务都负责引发事件。
In my definition either aggregates or domain services are responsible for emitting events.
所以您的一组事件看起来像一个概念,它表明一组相关事件对我的领域也很重要。
So your group of events looks like a concept that says that a group of related events is something important to my domain, too.
我想您可以采取两种方式考虑一下这个概念:
I guess you can go two ways to think about that concept:
- 一个小组是您已经发生的事件的一个特殊视图。那么组只是一个状态,该状态是从相关事件的列表中派生的。
- 组是一种聚合,是一种具有生命周期并基于状态的过程当满足完成小组的条件时发出单个小组事件
在第一种情况下,您可以实现一个监听发布的事件并将其投影到您的小组概念中
In the first case you can implement a group query that listens to published events and projects them to your group concept
在第二种情况下,您具有对业务请求做出反应的集合(可以将其称为命令)并管理一些持久状态。当您请求聚合创建组并且聚合处于执行此操作的正确状态时,聚合将发出一个组事件。
In the second case you have an aggregate that reacts to business requests (you can call this a command) and manages some persistent state. When you request your aggregate to create a group and your aggregate is in the right state to do this, then your aggregate emits a group event.
这篇关于如何使用域驱动设计为需求建模的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!