Eventual2PC 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Eventual2PC --version 1.0.0                
NuGet\Install-Package Eventual2PC -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Eventual2PC" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Eventual2PC --version 1.0.0                
#r "nuget: Eventual2PC, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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中的概念,作为事务相关消息路由的角色,负责响应 DomainEventDomainException 消息,并发送 Command 消息

Initiator 事件定义
  • TransactionStarted: 事务已发起事件

  • PreCommitSucceedParticipantAdded: 预提交成功的参与者已添加事件

  • PreCommitFailedParticipantAdded: 预提交失败的参与者已添加事件

  • AllParticipantPreCommitSucceed: 所有参与者预提交已成功事件

  • AnyParticipantPreCommitFailed: 任意一个参与者预提交已失败事件

  • CommittedParticipantAdded: 已提交的参与者已添加事件(Option)

  • RolledbackParticipantAdded: 已回滚的参与者已添加事件(Option)

  • TransactionCompleted: 事务已完成事件(Option),并包含是否事务已提交的状态

Participant 事件定义
  • PreCommitSucceed: 预提交已成功事件

  • PreCommitFailed: 预提交已失败事件(或领域异常消息)

  • Committed: 已提交事件

  • Rolledback: 已回滚事件

规范

  • 一个聚合根,可以同时扮演 InitiatorTransaction的角色,如银行转账事务聚合根

  • 一个聚合根,可以同时扮演事务A中的 Participant 和事务B的 Initiator

  • 一个 Participant,参与多少个事务,需对应定义多少个Preparation

  • Participant 的聚合根实例,允许同时参与多个不同的事务;也可以通过业务代码,在 PreCommit 时,判断是否存在其他类型的 Preparation 来阻止参与多个事务

  • Initiator 必须发布事件 TransactionStartedPreCommitSucceedParticipantAddedPreCommitFailedParticipantAddedAllParticipantPreCommitSucceedAnyParticipantPreCommitFailed

  • Participant 必须发布事件 PreCommitSucceedPreCommitFailedCommittedRolledback

  • 如果需要关注 Transaction 是否已完成,则 Initiator 需要发布事件 CommittedParticipantAddedRolledbackParticipantAddedTransactionCompleted

处理流程

  • Initiator 发布 TransactionStarted 事件;

  • ProcessManager 响应 TransactionStarted 事件,并发送 PreCommit 命令;

  • Participant 接受命令 PreCommit,如果成功,则发布 PreCommitSucceed 事件;如果失败,则发布 PreCommitFailed 事件(或领域异常);

  • ProcessManager 响应 PreCommitSucceed,并发送 AddPreCommitSucceedParticipant 命令;

  • ProcessManager 响应 PreCommitFailed,并发送 AddPreCommitFailedParticipant 命令;

  • Initiator 接受命令 AddPreCommitSucceedParticipant,发布 PreCommitSucceedParticipantAdded 事件;如果所有 ParticipantPreCommit 都已处理完成,则发布 AllParticipantPreCommitSucceed 事件;

  • Initiator 接受命令 AddPreCommitFailedParticipant,发布 PreCommitFailedParticipantAdded 事件;如果所有 ParticipantPreCommit 都已处理完成,则发布 AnyParticipantPreCommitFailed 事件;

  • ProcessManager 响应 AllParticipantPreCommitSucceed,并发送 Commit 命令;

  • ProcessManager 响应 AnyParticipantPreCommitFailed,并发送 Rollback 命令;

  • Participant 接受命令 Commit,并发布 Committed 事件;

  • Participant 接受命令 Rollback,并发布 Rolledback 事件;

  • ProcessManager 响应 Committed,并发送 AddCommittedParticipant 命令;

  • ProcessManager 响应 Rolledback,并发送 AddRolledbackParticipant 命令;

  • Initiator 接受命令 AddCommittedParticipant,发布 CommittedParticipantAdded 事件;如果所有 ParticipantCommit 都已处理完成,则发布 TransactionCompleted 事件;

  • Initiator 接受命令 AddRolledbackParticipant,发布 RolledbackParticipantAdded 事件;如果所有 ParticipantRolledback 都已处理完成,则发布 TransactionCompleted 事件。

发布历史

1.0.0(2020/4/25)

  • 初始版本
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .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.

Version Downloads Last updated
1.1.0 1,085 4/29/2020
1.0.2 745 4/27/2020
1.0.1 428 4/26/2020
1.0.0 1,383 4/25/2020

最终一致性二阶段提交范式,简化多聚合根之间交互事务的实现。任何基于cqrs + eda 实现多聚合根最终一致性的框架,都可使用。