Eventual2PC 1.0.0
See the version list below for details.
dotnet add package Eventual2PC --version 1.0.0
NuGet\Install-Package Eventual2PC -Version 1.0.0
<PackageReference Include="Eventual2PC" Version="1.0.0" />
paket add Eventual2PC --version 1.0.0
#r "nuget: Eventual2PC, 1.0.0"
// Install Eventual2PC as a Cake Addin #addin nuget:?package=Eventual2PC&version=1.0.0 // Install Eventual2PC as a Cake Tool #tool nuget:?package=Eventual2PC&version=1.0.0
Eventual2PC
最终一致性二阶段提交范式,简化多聚合根之间交互事务的实现。任何基于cqrs + eda 实现多聚合根最终一致性的框架,都可使用。
安装
dotnet add package Eventual2PC
范式
术语定义
Initiator
: 作为事务发起方,它是聚合根Participant
: 作为事务参与方(仅被修改的聚合根,新增的,不会产生业务失败问题),它是聚合根Preparation
: 事务准备,对应一个具体的业务修改动作;同一个Participant
参与多个事务时,应定义多个事务准备Transaction
: 2PC事务,从开始事务,到事务完成,贯穿整个事务生命周期;可以只是一个标识ID(通常使用TransactionStarted
事件的ID),也可以使用代表事务的聚合根(如银行转账的转账事务聚合根)ProcessManager
: CQRS中的概念,作为事务相关消息路由的角色,负责响应DomainEvent
、DomainException
消息,并发送Command
消息
Initiator 事件定义
TransactionStarted
: 事务已发起事件PreCommitSucceedParticipantAdded
: 预提交成功的参与者已添加事件PreCommitFailedParticipantAdded
: 预提交失败的参与者已添加事件AllParticipantPreCommitSucceed
: 所有参与者预提交已成功事件AnyParticipantPreCommitFailed
: 任意一个参与者预提交已失败事件CommittedParticipantAdded
: 已提交的参与者已添加事件(Option)RolledbackParticipantAdded
: 已回滚的参与者已添加事件(Option)TransactionCompleted
: 事务已完成事件(Option),并包含是否事务已提交的状态
Participant 事件定义
PreCommitSucceed
: 预提交已成功事件PreCommitFailed
: 预提交已失败事件(或领域异常消息)Committed
: 已提交事件Rolledback
: 已回滚事件
规范
一个聚合根,可以同时扮演
Initiator
和Transaction
的角色,如银行转账事务聚合根一个聚合根,可以同时扮演事务A中的
Participant
和事务B的Initiator
一个
Participant
,参与多少个事务,需对应定义多少个Preparation
Participant
的聚合根实例,允许同时参与多个不同的事务;也可以通过业务代码,在PreCommit
时,判断是否存在其他类型的Preparation
来阻止参与多个事务Initiator
必须发布事件TransactionStarted
、PreCommitSucceedParticipantAdded
、PreCommitFailedParticipantAdded
、AllParticipantPreCommitSucceed
、AnyParticipantPreCommitFailed
Participant
必须发布事件PreCommitSucceed
、PreCommitFailed
、Committed
、Rolledback
如果需要关注
Transaction
是否已完成,则Initiator
需要发布事件CommittedParticipantAdded
、RolledbackParticipantAdded
、TransactionCompleted
处理流程
Initiator
发布TransactionStarted
事件;ProcessManager
响应TransactionStarted
事件,并发送PreCommit
命令;Participant
接受命令PreCommit
,如果成功,则发布PreCommitSucceed
事件;如果失败,则发布PreCommitFailed
事件(或领域异常);ProcessManager
响应PreCommitSucceed
,并发送AddPreCommitSucceedParticipant
命令;ProcessManager
响应PreCommitFailed
,并发送AddPreCommitFailedParticipant
命令;Initiator
接受命令AddPreCommitSucceedParticipant
,发布PreCommitSucceedParticipantAdded
事件;如果所有Participant
的PreCommit
都已处理完成,则发布AllParticipantPreCommitSucceed
事件;Initiator
接受命令AddPreCommitFailedParticipant
,发布PreCommitFailedParticipantAdded
事件;如果所有Participant
的PreCommit
都已处理完成,则发布AnyParticipantPreCommitFailed
事件;ProcessManager
响应AllParticipantPreCommitSucceed
,并发送Commit
命令;ProcessManager
响应AnyParticipantPreCommitFailed
,并发送Rollback
命令;Participant
接受命令Commit
,并发布Committed
事件;Participant
接受命令Rollback
,并发布Rolledback
事件;ProcessManager
响应Committed
,并发送AddCommittedParticipant
命令;ProcessManager
响应Rolledback
,并发送AddRolledbackParticipant
命令;Initiator
接受命令AddCommittedParticipant
,发布CommittedParticipantAdded
事件;如果所有Participant
的Commit
都已处理完成,则发布TransactionCompleted
事件;Initiator
接受命令AddRolledbackParticipant
,发布RolledbackParticipantAdded
事件;如果所有Participant
的Rolledback
都已处理完成,则发布TransactionCompleted
事件。
发布历史
1.0.0(2020/4/25)
- 初始版本
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Eventual2PC:
Package | Downloads |
---|---|
ENode.Eventual2PC
基于Eventual2PC的最终一致性二阶段提交实现,用于ENode。 |
GitHub repositories
This package is not used by any popular GitHub repositories.
最终一致性二阶段提交范式,简化多聚合根之间交互事务的实现。任何基于cqrs + eda 实现多聚合根最终一致性的框架,都可使用。