From 42cceee2725d3a4befca189c08101f60ab3e5e75 Mon Sep 17 00:00:00 2001 From: dingsongjie Date: Fri, 6 Mar 2020 17:50:54 +0800 Subject: [PATCH] 调整命名 --- Pole.sln | 16 +++------------- samples/intergrationEvents/Product.IntegrationEvents/Product.IntegrationEvents.csproj | 7 ------- samples/intergrationEvents/Product.IntegrationEvents/ProductAddedIntegrationEvent.cs | 15 --------------- samples/proto/common/commonCommandResponse.proto | 10 ---------- samples/proto/service/Order/order.proto | 28 ---------------------------- samples/proto/service/Product/product.proto | 24 ------------------------ samples/proto/service/Product/productType.proto | 17 ----------------- src/Pole.Sagas/Core/Saga.cs | 40 ++++++++++++++++++++++++++-------------- 8 files changed, 29 insertions(+), 128 deletions(-) delete mode 100644 samples/intergrationEvents/Product.IntegrationEvents/Product.IntegrationEvents.csproj delete mode 100644 samples/intergrationEvents/Product.IntegrationEvents/ProductAddedIntegrationEvent.cs delete mode 100644 samples/proto/common/commonCommandResponse.proto delete mode 100644 samples/proto/service/Order/order.proto delete mode 100644 samples/proto/service/Product/product.proto delete mode 100644 samples/proto/service/Product/productType.proto diff --git a/Pole.sln b/Pole.sln index 4ffabfb..8bc9b96 100644 --- a/Pole.sln +++ b/Pole.sln @@ -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} diff --git a/samples/intergrationEvents/Product.IntegrationEvents/Product.IntegrationEvents.csproj b/samples/intergrationEvents/Product.IntegrationEvents/Product.IntegrationEvents.csproj deleted file mode 100644 index 9f5c4f4..0000000 --- a/samples/intergrationEvents/Product.IntegrationEvents/Product.IntegrationEvents.csproj +++ /dev/null @@ -1,7 +0,0 @@ - - - - netstandard2.0 - - - diff --git a/samples/intergrationEvents/Product.IntegrationEvents/ProductAddedIntegrationEvent.cs b/samples/intergrationEvents/Product.IntegrationEvents/ProductAddedIntegrationEvent.cs deleted file mode 100644 index 71c07b6..0000000 --- a/samples/intergrationEvents/Product.IntegrationEvents/ProductAddedIntegrationEvent.cs +++ /dev/null @@ -1,15 +0,0 @@ -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; } - } -} diff --git a/samples/proto/common/commonCommandResponse.proto b/samples/proto/common/commonCommandResponse.proto deleted file mode 100644 index d9ff0c9..0000000 --- a/samples/proto/common/commonCommandResponse.proto +++ /dev/null @@ -1,10 +0,0 @@ -syntax = "proto3"; - - -package pole.Grpc.ExtraType; - -message CommonCommandResponse { - // 1 成功 2 失败 - int32 status = 1; - string message = 2; -} \ No newline at end of file diff --git a/samples/proto/service/Order/order.proto b/samples/proto/service/Order/order.proto deleted file mode 100644 index f90639c..0000000 --- a/samples/proto/service/Order/order.proto +++ /dev/null @@ -1,28 +0,0 @@ -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 diff --git a/samples/proto/service/Product/product.proto b/samples/proto/service/Product/product.proto deleted file mode 100644 index e9ccd7b..0000000 --- a/samples/proto/service/Product/product.proto +++ /dev/null @@ -1,24 +0,0 @@ -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 diff --git a/samples/proto/service/Product/productType.proto b/samples/proto/service/Product/productType.proto deleted file mode 100644 index eccf85f..0000000 --- a/samples/proto/service/Product/productType.proto +++ /dev/null @@ -1,17 +0,0 @@ -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; -} diff --git a/src/Pole.Sagas/Core/Saga.cs b/src/Pole.Sagas/Core/Saga.cs index 72b794e..c0f3ce2 100644 --- a/src/Pole.Sagas/Core/Saga.cs +++ b/src/Pole.Sagas/Core/Saga.cs @@ -18,18 +18,18 @@ namespace Pole.Sagas.Core private ISnowflakeIdGenerator snowflakeIdGenerator; private IActivityFinder activityFinder; private PoleSagasOption poleSagasOption; - public int CurrentMaxOrder + private int CurrentMaxOrder { get { return activities.Count; } } /// /// 如果 等于 -1 说明已经在执行补偿操作,此时这个值已经没有意义 /// - private int _currentExecuteOrder = 0; + private int currentExecuteOrder = 0; /// /// 如果 等于 -1 说明已经还未执行补偿操作,此时这个值没有意义 /// - 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 CompensateActivity(ActivityExecuteResult result,int currentCompensateOrder) { - _currentCompensateOrder = currentCompensateOrder; - _currentExecuteOrder = -1; + this.currentCompensateOrder = currentCompensateOrder; + currentExecuteOrder = -1; var compensateActivity = GetNextCompensateActivity(); if (compensateActivity == null) { -- libgit2 0.25.0