simgroep/event-sourcing
最新稳定版本:0.1.0
Composer 安装命令:
composer require simgroep/event-sourcing
包简介
README 文档
README
Provides several components on top of broadway.
Concurrency
Updating an aggregate root at the same time may lead to concurrency problems. To solve this we provide a CommandGateway and a LockingRepository, inspired by the Axon Framework.
The LockingRepository will prevent access to the repository once load() is called. When save() is called, the lock will be released. Trying to access the repository while being locked will result in a ConcurrencyException.
The CommandGateway will in turn catch the ConcurrencyException, and will try do dispatch the command again until a specific condition is met (depends on the used Scheduler implementation), or throw the ConcurrencyException otherwise.
Replaying Events
The EventSourcingBundle contains commands to make interactive replaying of events available after doing a few simple steps.
Mark projectors for replaying
The bundle needs to be aware which projectors are replayable and what there corresponding repositories are.
Projectors are tagged by 'projector.replayable' and the 'repository attribute' is used to define the repository.
For example:
sim.read_model.projector.municipality_hostname: class: SIM\Settings\ReadModel\MunicipalityHostnameProjector arguments: [@sim.read_model.repository.municipality_hostname] tags: - { name: broadway.domain.event_listener } - { name: projector.replayable, repository: sim.read_model.repository.municipality_hostname}
Test if your projectors are correctly tagged as replayable
After tagging your projectors you can test the outcome with the next command: (don't forget to clear the symfony cache.)
vagrant@dev:/var/www/someproject-api$ php ./app/console simgroep:eventsourcing:projectors:list
The following projectors are available for rebuilding:
- sim.read_model.repository.municipality_hostname
You can directly see if your projectors are marked for rebuilding their projections.
Replay time
Now it's time for the fun part ...replaying!. There are three forms of replaying:
- non-interactive replaying (multi threaded)
- replay a specific stream of events
- interactive replaying
Non-interactive replaying
Non-interactive replaying is straight forward.
php ./app/console simgroep:eventsourcing:events:replay --threads 4 all
- You can define a specific projector (ex: php ./app/console simgroep:eventsourcing:events:replay municipality_hostname).
- You can define multiple projectors (ex: php ./app/console simgroep:eventsourcing:events:replay 'projector1,projector2').
- A third option is to define all projectors (ex: php ./app/console simgroep:eventsourcing:events:replay all).
With "--threads" you can define the number of threads. The maximum number of threads is the number of cpu cores * 2.
Note: "--threads" cannot be used with interactive mode or when replaying a specific stream
Replay a specific stream of events
If you want to replay only the events from a specific stream then
php ./app/console simgroep:eventsourcing:events:replay --stream 00000000-0000-0000-0000-000000000000 all
Interactive replaying
When time travelling becomes important for debugging purposes then you can choose for interactive replaying of your event store.
Interactive replaying contains one extra argument (--interact) and a value which contains the stream id.
php ./app/console simgroep:eventsourcing:events:replay --interact 00000000-0000-0000-0000-000000000000 all
Every event of the event store will be replayed, if one those events contains the supplied stream id and hits one of the selected projectors then:
- The event will be replayed first and the first projection will be updated.
- The replaying will pause if gives you the option to continue or stop replaying.
- If multiple projectors are affected by this event then the next projector will be updated and we will go back to step 2.
simgroep/event-sourcing 适用场景与选型建议
simgroep/event-sourcing 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 832 次下载、GitHub Stars 达 8, 最近一次更新时间为 2015 年 04 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 simgroep/event-sourcing 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 simgroep/event-sourcing 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 832
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2015-04-17