Git Product home page Git Product logo

654894017 / cqrs Goto Github PK

View Code? Open in Web Editor NEW
39.0 2.0 31.0 686 KB

cqrs是基于事件回溯的高性能架构,主要针对单个领域业务高度复杂且需要高性能的业务场景,可以说它能够作为高并发系统的通用解决方案。例如:秒杀、抢红包、12306卖票等。基于事件溯源,实现cqrs最复杂的模型, 通过事件是追加的特性,然后结合事件批量提交的手段,避免在高并发更新时多个线程update带来的严重锁冲突问题,从而来实现高性能。 支持聚合回溯,包括扩容、缩容聚合冲突事件回溯、聚合根在内存、聚合根快照、聚合事件组提交,可集成dubbo、spring cloud。

License: Apache License 2.0

Java 100.00%
cqrs event-sourcing in-memory dubbo spring-cloud group-commit event-mailbox ddd rocketmq kafka

cqrs's Introduction

cqrs

cqrs是基于事件回溯的高性能架构,主要针对单个领域业务高度复杂且需要高性能的业务场景,可以说它能够作为高并发系统的通用解决方案。例如:秒杀、抢红包、12306卖票等。基于事件溯源,实现cqrs最复杂的模型, 通过事件是追加的特性,然后结合事件批量提交的手段,避免在高并发更新时多个线程update带来的严重锁冲突问题,从而来实现高性能。 支持聚合回溯,包括扩容、缩容聚合冲突事件回溯、聚合根在内存、聚合根快照、聚合事件组提交,可集成dubbo、spring cloud。注意:并未支持saga业务编排,由业务方自己去编排。

架构概述

架构图

使用示例:

//1.初始化商品库存管理服务

GoodsStockService service = new GoodsStockService(committingService);

//2.初始化商品

GoodsAddCommand command = new GoodsAddCommand(IdWorker.getId(), 2, "iphone 6 plus", 1000);

Goods goods1 = service.process(command, () -> new Goods(2, command.getName(), command.getCount())).join();

//3.库存+1

GoodsStockAddCommand command = new GoodsStockAddCommand(IdWorker.getId(), 2);

Goods goods2 = service.process(command, goods -> goods.addStock(1)).join();

注意事项

1.如果使用dubbo、spring cloud负载均衡策略请选择一致性hash,这样可以减少在集群扩容、缩容聚合根回溯的成本。

2.关闭dubbo、spring cloud的失败重试。

3.Dubbo服务抛出该异常AggregateEventConflictException,客户端可以重新发起请求。( 出现此异常的原因是当前聚合根在多个实例中存在(集群扩容时),可以捕获此异常然后重新在client发起调用,当前的请求会负载到新的实例上。)

4.mysql 需要开启 rewriteBatchedStatements 批量操作选项,否则性能不佳。

测试报告

CPU:I7-3740QM(4核8线程) 24G内存 mysql 5.7 ssd(早期固态硬盘) jdk1.8

性能数据:

商品添加:6.5K TPS/s

单个商品库存添加:14K TPS/S

三个商品库存添加:30K TPS/S mysql cpu:18% mysql内存占用:300M , jvm cpu: 20% jvm 内存占用:1.8G

cqrs's People

Contributors

654894017 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cqrs's Issues

答疑

请问一下,后面是如何把事件同步到query侧的db中的,看到了kafka和rocketmp的相关的代码,但是不太明白是如何进行队列监听并传送数据的,并且看架构图是实现了query侧db的更新的,但是在代码中好像没看到这块,期待您的回答,感谢

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.