Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

领域事件的发出和消费放哪层呀 #394

Open
patinousward opened this issue Feb 16, 2023 · 4 comments
Open

领域事件的发出和消费放哪层呀 #394

patinousward opened this issue Feb 16, 2023 · 4 comments

Comments

@patinousward
Copy link

目前4.0,ddd变成可选的了,如果想进行ddd,那么领域事件放哪层比较合适,infrastructure?

@allenbin
Copy link

allenbin commented Aug 4, 2023

在infrastructure层只是定义了事件发布的接口和具体的事件总线实现,
发布: 但领域事件本身是属于领域内的产物,一般我们在app中执行完用例代码调用基础设施层发布领域事件,不过也见过人把领域事件当成数据存储起来,再进行异步发送,保证其完整性!个人认为为了简单的话直接放在app中去发布即可,一致性要求较高的可以用rocketmq的ack机制保证(先发布事件)。
消费:官方文档中是注明在app层进行消费,包括xxl-job等任务的执行也是在app层

@allenbin
Copy link

allenbin commented Aug 4, 2023

在infrastructure层只是定义了事件发布的接口和具体的事件总线实现, 但领域事件本身是属于领域内的产物,一般我们在app中执行完用例代码调用基础设施层发布领域事件,不过也见过人把领域事件当成数据存储起来,再进行异步发送,保证其完整性!个人认为为了简单的话直接放在app中去发布即可,一致性要求较高的可以用rocketmq的ack机制保证(先发布事件)。

@1394267714
Copy link

我也想问,如果用spring做eventbus,这种事件类定义在哪,又在哪进行发布和订阅

@amerina
Copy link

amerina commented May 29, 2024

领域事件是领域层发布的,想DDD的话领域事件应该在聚合根的方法中创建并发布。在聚合根的状态发生变更时(比如,订单状态从“新建”变为“已支付”),聚合根可能会创建并发布一个领域事件(比如,“订单已支付”事件)。

领域服务可以订阅这些领域事件,并在事件发生时执行相应的业务逻辑。例如,一个领域服务可能会订阅“订单已支付”事件,并在接收到事件时更新库存。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants