Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
丁松杰
/
Pole
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
42cceee2
authored
5 years ago
by
dingsongjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调整命名
parent
1fffdf16
master
…
v1.0.0
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
29 additions
and
131 deletions
Pole.sln
samples/intergrationEvents/Product.IntegrationEvents/Product.IntegrationEvents.csproj
samples/intergrationEvents/Product.IntegrationEvents/ProductAddedIntegrationEvent.cs
samples/proto/common/commonCommandResponse.proto
samples/proto/service/Order/order.proto
samples/proto/service/Product/product.proto
samples/proto/service/Product/productType.proto
src/Pole.Sagas/Core/Saga.cs
Pole.sln
View file @
42cceee2
...
...
@@ -25,10 +25,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Backet.Api", "samples\apis\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "User.Api", "samples\apis\User.Api\User.Api.csproj", "{F65858EC-C34F-4121-BEC5-4E20DEA74A0A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "integrationEvents", "integrationEvents", "{74422E64-29FE-4287-A86E-741D1DFF6698}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Product.IntegrationEvents", "samples\intergrationEvents\Product.IntegrationEvents\Product.IntegrationEvents.csproj", "{9C0DFC90-1AF9-424A-B5FB-2A7C3611970C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pole.EventBus.Rabbitmq", "src\Pole.EventBus.Rabbitmq\Pole.EventBus.Rabbitmq.csproj", "{BDF62A19-FFBD-4EE1-A07A-68472E680A95}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pole.Core.Test", "test\Pole.Core.Test\Pole.Core.Test.csproj", "{23EA8735-DB2E-4599-8902-8FCBCBE4799C}"
...
...
@@ -39,11 +35,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pole.Orleans.Provider.Entit
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pole.Samples.Backet.Api", "test\Pole.Samples.Backet.Api\Pole.Samples.Backet.Api.csproj", "{FB3D2F52-123A-4606-B682-9159BD7913AE}"
EndProject
Project("{
FAE04EC0-301F-11D3-BF4B-00C04F79EFBC
}") = "Pole.Sagas", "src\Pole.Sagas\Pole.Sagas.csproj", "{1F06D877-E4EC-4908-9057-38EDCE5E54E6}"
Project("{
9A19103F-16F7-4668-BE54-9A1E7A4F7556
}") = "Pole.Sagas", "src\Pole.Sagas\Pole.Sagas.csproj", "{1F06D877-E4EC-4908-9057-38EDCE5E54E6}"
EndProject
Project("{
FAE04EC0-301F-11D3-BF4B-00C04F79EFBC
}") = "Pole.Sagas.Storage.PostgreSql", "src\Pole.Sagas.Storage.PostgreSql\Pole.Sagas.Storage.PostgreSql.csproj", "{9505BDFC-395B-4257-AEB3-2B44611147A4}"
Project("{
9A19103F-16F7-4668-BE54-9A1E7A4F7556
}") = "Pole.Sagas.Storage.PostgreSql", "src\Pole.Sagas.Storage.PostgreSql\Pole.Sagas.Storage.PostgreSql.csproj", "{9505BDFC-395B-4257-AEB3-2B44611147A4}"
EndProject
Project("{
FAE04EC0-301F-11D3-BF4B-00C04F79EFBC
}") = "SagasTest.Api", "samples\apis\SagasTest.Api\SagasTest.Api.csproj", "{6138197E-6202-4E1B-9458-3CBEE60A36F9}"
Project("{
9A19103F-16F7-4668-BE54-9A1E7A4F7556
}") = "SagasTest.Api", "samples\apis\SagasTest.Api\SagasTest.Api.csproj", "{6138197E-6202-4E1B-9458-3CBEE60A36F9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
...
...
@@ -75,10 +71,6 @@ Global
{F65858EC-C34F-4121-BEC5-4E20DEA74A0A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F65858EC-C34F-4121-BEC5-4E20DEA74A0A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F65858EC-C34F-4121-BEC5-4E20DEA74A0A}.Release|Any CPU.Build.0 = Release|Any CPU
{9C0DFC90-1AF9-424A-B5FB-2A7C3611970C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9C0DFC90-1AF9-424A-B5FB-2A7C3611970C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9C0DFC90-1AF9-424A-B5FB-2A7C3611970C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9C0DFC90-1AF9-424A-B5FB-2A7C3611970C}.Release|Any CPU.Build.0 = Release|Any CPU
{BDF62A19-FFBD-4EE1-A07A-68472E680A95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BDF62A19-FFBD-4EE1-A07A-68472E680A95}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BDF62A19-FFBD-4EE1-A07A-68472E680A95}.Release|Any CPU.ActiveCfg = Release|Any CPU
...
...
@@ -124,8 +116,6 @@ Global
{125B1E4B-B1C1-4F85-9C6A-38815960E654} = {475116FC-DEEC-4255-94E4-AE7B8C85038D}
{C961F25C-1C11-4855-84E4-ADABE96451E7} = {475116FC-DEEC-4255-94E4-AE7B8C85038D}
{F65858EC-C34F-4121-BEC5-4E20DEA74A0A} = {475116FC-DEEC-4255-94E4-AE7B8C85038D}
{74422E64-29FE-4287-A86E-741D1DFF6698} = {4A0FB696-EC29-4A5F-B40B-A6FC56001ADB}
{9C0DFC90-1AF9-424A-B5FB-2A7C3611970C} = {74422E64-29FE-4287-A86E-741D1DFF6698}
{BDF62A19-FFBD-4EE1-A07A-68472E680A95} = {9932C965-8B38-4F70-9E43-86DC56860E2B}
{23EA8735-DB2E-4599-8902-8FCBCBE4799C} = {655E719B-4A3E-467C-A541-E0770AB81DE1}
{548EFDBB-252F-48DD-87F4-58ABFBD4963C} = {9932C965-8B38-4F70-9E43-86DC56860E2B}
...
...
This diff is collapsed.
Click to expand it.
samples/intergrationEvents/Product.IntegrationEvents/Product.IntegrationEvents.csproj
deleted
100644 → 0
View file @
1fffdf16
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>
This diff is collapsed.
Click to expand it.
samples/intergrationEvents/Product.IntegrationEvents/ProductAddedIntegrationEvent.cs
deleted
100644 → 0
View file @
1fffdf16
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
namespace
Product.IntegrationEvents
{
public
class
ProductAddedIntegrationEvent
{
public
string
BacketId
{
get
;
set
;
}
public
string
ProductId
{
get
;
set
;
}
public
string
ProductName
{
get
;
set
;
}
public
long
Price
{
get
;
set
;
}
}
}
This diff is collapsed.
Click to expand it.
samples/proto/common/commonCommandResponse.proto
deleted
100644 → 0
View file @
1fffdf16
syntax
=
"proto3"
;
package
pole
.
Grpc.ExtraType
;
message
CommonCommandResponse
{
// 1 成功 2 失败
int32
status
=
1
;
string
message
=
2
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
samples/proto/service/Order/order.proto
deleted
100644 → 0
View file @
1fffdf16
syntax
=
"proto3"
;
package
newArchitectureLab
.
apps.order
;
service
Order
{
rpc
GetById
(
GetByIdRequest
)
returns
(
GetByIdResponse
);
}
message
GetByIdRequest
{
string
id
=
1
;
}
message
GetByIdResponse
{
string
id
=
1
;
double
totalprice
=
2
;
repeated
Product
products
=
3
;
message
Product
{
string
id
=
1
;
string
name
=
2
;
double
price
=
3
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
samples/proto/service/Product/product.proto
deleted
100644 → 0
View file @
1fffdf16
syntax
=
"proto3"
;
package
newArchitectureLab
.
apps.product
;
// The product service definition.
service
Product
{
rpc
GetById
(
GetByIdRequest
)
returns
(
GetByIdResponse
);
}
message
GetByIdRequest
{
string
Id
=
1
;
}
message
GetByIdResponse
{
string
id
=
1
;
string
name
=
2
;
double
price
=
3
;
int64
stock
=
4
;
string
productTypeId
=
5
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
samples/proto/service/Product/productType.proto
deleted
100644 → 0
View file @
1fffdf16
syntax
=
"proto3"
;
import
"common/commonCommandResponse.proto"
;
package
poleSample
.
apis.product
;
// The greeting service definition.
service
ProductType
{
// Sends a greeting
rpc
Add
(
AddProductTypeRequest
)
returns
(
pole.Grpc.ExtraType.CommonCommandResponse
);
}
// The request message containing the user's name.
message
AddProductTypeRequest
{
string
id
=
1
;
string
name
=
2
;
}
This diff is collapsed.
Click to expand it.
src/Pole.Sagas/Core/Saga.cs
View file @
42cceee2
...
...
@@ -18,18 +18,18 @@ namespace Pole.Sagas.Core
private
ISnowflakeIdGenerator
snowflakeIdGenerator
;
private
IActivityFinder
activityFinder
;
private
PoleSagasOption
poleSagasOption
;
p
ublic
int
CurrentMaxOrder
p
rivate
int
CurrentMaxOrder
{
get
{
return
activities
.
Count
;
}
}
/// <summary>
/// 如果 等于 -1 说明已经在执行补偿操作,此时这个值已经没有意义
/// </summary>
private
int
_currentExecuteOrder
=
0
;
private
int
currentExecuteOrder
=
0
;
/// <summary>
/// 如果 等于 -1 说明已经还未执行补偿操作,此时这个值没有意义
/// </summary>
private
int
_
currentCompensateOrder
=
-
1
;
private
int
currentCompensateOrder
=
-
1
;
private
ISerializer
serializer
;
public
string
Id
{
get
;
}
...
...
@@ -43,6 +43,18 @@ namespace Pole.Sagas.Core
this
.
activityFinder
=
activityFinder
;
Id
=
snowflakeIdGenerator
.
NextId
();
}
internal
Saga
(
ISnowflakeIdGenerator
snowflakeIdGenerator
,
IServiceProvider
serviceProvider
,
IEventSender
eventSender
,
PoleSagasOption
poleSagasOption
,
ISerializer
serializer
,
IActivityFinder
activityFinder
,
int
currentExecuteOrder
,
int
currentCompensateOrder
)
{
this
.
snowflakeIdGenerator
=
snowflakeIdGenerator
;
this
.
serviceProvider
=
serviceProvider
;
this
.
eventSender
=
eventSender
;
this
.
poleSagasOption
=
poleSagasOption
;
this
.
serializer
=
serializer
;
this
.
activityFinder
=
activityFinder
;
Id
=
snowflakeIdGenerator
.
NextId
();
this
.
currentExecuteOrder
=
currentExecuteOrder
;
this
.
currentCompensateOrder
=
currentCompensateOrder
;
}
public
void
AddActivity
(
string
activityName
,
object
data
,
int
timeOutSeconds
=
2
)
{
...
...
@@ -84,22 +96,22 @@ namespace Pole.Sagas.Core
private
ActivityWapper
GetNextExecuteActivity
()
{
if
(
_
currentExecuteOrder
==
CurrentMaxOrder
)
if
(
currentExecuteOrder
==
CurrentMaxOrder
)
{
return
null
;
}
_
currentExecuteOrder
++;
return
activities
[
_
currentExecuteOrder
-
1
];
currentExecuteOrder
++;
return
activities
[
currentExecuteOrder
-
1
];
}
private
ActivityWapper
GetNextCompensateActivity
()
{
_
currentCompensateOrder
--;
if
(
_
currentCompensateOrder
==
0
)
currentCompensateOrder
--;
if
(
currentCompensateOrder
==
0
)
{
return
null
;
}
return
activities
[
_
currentCompensateOrder
-
1
];
return
activities
[
currentCompensateOrder
-
1
];
}
private
async
Task
RecursiveCompensateActivity
(
ActivityWapper
activityWapper
)
{
...
...
@@ -133,7 +145,7 @@ namespace Pole.Sagas.Core
if
(!
result
.
IsSuccess
)
{
await
eventSender
.
ActivityRevoked
(
activityId
);
await
CompensateActivity
(
result
,
_
currentExecuteOrder
);
await
CompensateActivity
(
result
,
currentExecuteOrder
);
return
result
;
}
await
eventSender
.
ActivityEnded
(
activityId
,
string
.
Empty
);
...
...
@@ -159,7 +171,7 @@ namespace Pole.Sagas.Core
};
await
eventSender
.
ActivityExecuteOvertime
(
activityId
,
Id
,
errors
);
// 超时的时候 需要首先补偿这个超时的操作
return
await
CompensateActivity
(
result
,
_
currentExecuteOrder
+
1
);
return
await
CompensateActivity
(
result
,
currentExecuteOrder
+
1
);
}
else
{
...
...
@@ -171,15 +183,15 @@ namespace Pole.Sagas.Core
};
await
eventSender
.
ActivityExecuteAborted
(
activityId
,
errors
);
// 出错的时候 需要首先补偿这个出错的操作
return
await
CompensateActivity
(
result
,
_
currentExecuteOrder
+
1
);
return
await
CompensateActivity
(
result
,
currentExecuteOrder
+
1
);
}
}
}
private
async
Task
<
ActivityExecuteResult
>
CompensateActivity
(
ActivityExecuteResult
result
,
int
currentCompensateOrder
)
{
_
currentCompensateOrder
=
currentCompensateOrder
;
_
currentExecuteOrder
=
-
1
;
this
.
currentCompensateOrder
=
currentCompensateOrder
;
currentExecuteOrder
=
-
1
;
var
compensateActivity
=
GetNextCompensateActivity
();
if
(
compensateActivity
==
null
)
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment