-
Notifications
You must be signed in to change notification settings - Fork 23
/
Program.cs
52 lines (46 loc) · 1.95 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using FreeSql;
using System;
using System.Threading.Tasks;
namespace net60_tcc_saga
{
class Program
{
async static Task Main(string[] args)
{
DB.Cloud.Insert(new User { Id = 1, Name = "testuser01", Point = 10 }).ExecuteAffrows();
DB.Cloud.Insert(new Goods { Id = 1, Title = "testgoods01", Stock = 0 }).ExecuteAffrows();
await TestTcc();
await TestSaga();
Console.ReadKey();
DB.Cloud.Dispose();
}
async static Task TestTcc()
{
var orderId = Guid.NewGuid();
await DB.Cloud.StartTcc(orderId.ToString(), "支付购买TCC事务",
new TccOptions
{
MaxRetryCount = 10,
RetryInterval = TimeSpan.FromSeconds(10)
})
.Then<Tcc1>(DbEnum.db1, new TccUnit1State { UserId = 1, Point = 10, GoodsId = 1, OrderId = orderId })
.Then<Tcc2>(DbEnum.db2, new TccUnit2State { UserId = 1, Point = 10, GoodsId = 1, OrderId = orderId })
.Then<Tcc3>(DbEnum.db3, new TccUnit3State { UserId = 1, Point = 10, GoodsId = 1, OrderId = orderId })
.ExecuteAsync();
}
async static Task TestSaga()
{
var orderId = Guid.NewGuid();
await DB.Cloud.StartSaga(orderId.ToString(), "支付购买SAGA事务",
new SagaOptions
{
MaxRetryCount = 10,
RetryInterval = TimeSpan.FromSeconds(10)
})
.Then<Saga1>(DbEnum.db1, new SagaUnit1State { UserId = 1, Point = 10, GoodsId = 1, OrderId = orderId })
.Then<Saga2>(DbEnum.db2, new SagaUnit2State { UserId = 1, Point = 10, GoodsId = 1, OrderId = orderId })
.Then<Saga3>(DbEnum.db3, new SagaUnit3State { UserId = 1, Point = 10, GoodsId = 1, OrderId = orderId })
.ExecuteAsync();
}
}
}