bytedance / dddfirework Goto Github PK
View Code? Open in Web Editor NEWLicense: Apache License 2.0
License: Apache License 2.0
事件异步处理是一个十分常见的业务场景,通过eventbus可方便发送和处理异步事件。
异步事件带来便利的同时,也容易把问题隐藏起来,发现和定位问题变困难了。为了加速问题发现和定位,需要eventbus提供观测能力,通过监控指标暴露当期事件处理情况:处理速度、积压情况、处理延迟、失败率等。
当前如果用户事件函数 panic,会触发事件失败策略,反复消费该事件,引起反复 panic,然后进程无法重启,框架应该考虑优化的方案
定时任务是一个十分常见的业务场景,例如每天凌晨 1 点刷新用户成就。当前也有很多成熟的外部方案,例如 k8s 的 Cronjob,带有定时器的 FaaS ,还有很多支持分布式定时器的三方组件。
由框架本身集成定时功能具有很多好处:1,业务逻辑可以更好内聚到领域层,开发定时任务跟开发一个普通的应用层 Command 一样;2,业务侵入性更低,接入定时不需要做过多的代码改造;3,贯彻框架“隔离业务与技术复杂度”的宗旨。
Mysql executor receive a gorm.DB, and gorm.DB have many drivers, e.g. postgres sqlite.
So sql
is more proper?
dddfirework/executor/mysql/executor.go
Line 127 in 3ddc321
当前,在 Act 方法中删除聚合根的操作有较大歧义,开发者很容易会忘记在 Build 中返回,而直接通过 RootContainer.Remove 方法删除一个新建的聚合根,导致删除失败。
究其原因,RootContainer.Remove 的方法接受一个聚合根,语义上未明确是必须 “在 RootContainer 里面的聚合根”,并且该方法没有直接返回错误。
我们可以做以下改进:
修改 Act 方法签名为 "Act(ctx context.Context, container ddd.RootContainer) error" ,把 roots ...ddd.IEntity 参数去掉,同时在 RootContainer 新增 GetRoot 方法获取 Build 方法中返回的聚合根。好处是让用户建立 RootContainer 即接受 Build 参数的容器的概念,从而 Remove 也自然需要是已经在容器中的聚合根。
在 RootContainer.Remove 增加错误返回,强化传入一个非法聚合根的错误提示。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.