From 7b9deacf8fc15987bedc01f4d673e6b1c95d4fcc Mon Sep 17 00:00:00 2001 From: Catcher Wong Date: Tue, 30 Aug 2022 22:38:01 +0800 Subject: [PATCH] feat: saga support retrylimit (#56) --- build/version.props | 2 +- src/DtmCommon/Imp/TransBase.cs | 6 ++++++ src/Dtmcli/Saga/Saga.cs | 11 +++++++++++ src/Dtmgrpc/DtmgRPCClient.cs | 1 + src/Dtmgrpc/Saga/SagaGrpc.cs | 11 +++++++++++ src/Dtmgrpc/dtmgpb/dtmgimp.proto | 2 ++ tests/Dtmcli.Tests/SagaTests.cs | 2 ++ tests/Dtmgrpc.Tests/SagaTests.cs | 2 ++ 8 files changed, 36 insertions(+), 1 deletion(-) diff --git a/build/version.props b/build/version.props index 94c09bf..436f22f 100644 --- a/build/version.props +++ b/build/version.props @@ -1,7 +1,7 @@ - 1.2.0 + 1.3.0 diff --git a/src/DtmCommon/Imp/TransBase.cs b/src/DtmCommon/Imp/TransBase.cs index 5efd5ab..e958473 100644 --- a/src/DtmCommon/Imp/TransBase.cs +++ b/src/DtmCommon/Imp/TransBase.cs @@ -26,6 +26,12 @@ public class TransBase [JsonPropertyName("branch_headers")] public Dictionary BranchHeaders { get; set; } + [JsonPropertyName("retry_limit")] + public long RetryLimit { get; set; } + + [JsonPropertyName("retry_count")] + public long RetryCount { get; set; } + /// /// use in MSG/SAGA /// diff --git a/src/Dtmcli/Saga/Saga.cs b/src/Dtmcli/Saga/Saga.cs index 5f88d3a..25d47ad 100644 --- a/src/Dtmcli/Saga/Saga.cs +++ b/src/Dtmcli/Saga/Saga.cs @@ -96,5 +96,16 @@ public Saga SetBranchHeaders(Dictionary headers) this._transBase.BranchHeaders = headers; return this; } + + /// + /// Set global trans retry limit + /// + /// + /// + public Saga SetRetryLimit(long limit) + { + this._transBase.RetryLimit = limit; + return this; + } } } diff --git a/src/Dtmgrpc/DtmgRPCClient.cs b/src/Dtmgrpc/DtmgRPCClient.cs index d346cd5..47f3ccb 100644 --- a/src/Dtmgrpc/DtmgRPCClient.cs +++ b/src/Dtmgrpc/DtmgRPCClient.cs @@ -104,6 +104,7 @@ private dtmgpb.DtmRequest BuildDtmRequest(TransBase transBase) WaitResult = transBase.WaitResult, TimeoutToFail = transBase.TimeoutToFail, RetryInterval = transBase.RetryInterval, + RetryLimit = transBase.RetryLimit, }; if (transBase.BranchHeaders != null) diff --git a/src/Dtmgrpc/Saga/SagaGrpc.cs b/src/Dtmgrpc/Saga/SagaGrpc.cs index ebe4bf0..6d6ae16 100644 --- a/src/Dtmgrpc/Saga/SagaGrpc.cs +++ b/src/Dtmgrpc/Saga/SagaGrpc.cs @@ -99,5 +99,16 @@ public SagaGrpc SetBranchHeaders(Dictionary headers) this._transBase.BranchHeaders = headers; return this; } + + /// + /// Set global trans retry limit + /// + /// + /// + public SagaGrpc SetRetryLimit(long limit) + { + this._transBase.RetryLimit = limit; + return this; + } } } diff --git a/src/Dtmgrpc/dtmgpb/dtmgimp.proto b/src/Dtmgrpc/dtmgpb/dtmgimp.proto index bcf4a0e..05522a4 100644 --- a/src/Dtmgrpc/dtmgpb/dtmgimp.proto +++ b/src/Dtmgrpc/dtmgpb/dtmgimp.proto @@ -21,6 +21,8 @@ message DtmTransOptions { int64 RetryInterval = 3; // repeated string PassthroughHeaders = 4; map BranchHeaders = 5; + int64 RequestTimeout = 6; + int64 RetryLimit = 7; } // DtmRequest request sent to dtm server diff --git a/tests/Dtmcli.Tests/SagaTests.cs b/tests/Dtmcli.Tests/SagaTests.cs index 5860175..2f78df3 100644 --- a/tests/Dtmcli.Tests/SagaTests.cs +++ b/tests/Dtmcli.Tests/SagaTests.cs @@ -40,6 +40,7 @@ public async void Submit_Should_Succeed() .EnableWaitResult() .SetRetryInterval(10) .SetTimeoutToFail(100) + .SetRetryLimit(2) .SetBranchHeaders(new Dictionary { { "bh1", "123" }, @@ -123,6 +124,7 @@ protected override async Task SendAsync(HttpRequestMessage Assert.Contains("bh2", transBase.BranchHeaders.Keys); Assert.Equal(4, transBase.Payloads.Count); Assert.Equal(4, transBase.Steps.Count); + Assert.Equal(2, transBase.RetryLimit); var content = new StringContent("{\"dtm_result\":\"SUCCESS\"}"); diff --git a/tests/Dtmgrpc.Tests/SagaTests.cs b/tests/Dtmgrpc.Tests/SagaTests.cs index de3fade..cea7b40 100644 --- a/tests/Dtmgrpc.Tests/SagaTests.cs +++ b/tests/Dtmgrpc.Tests/SagaTests.cs @@ -31,6 +31,7 @@ public async void Submit_Should_Succeed() .EnableConcurrent() .SetRetryInterval(10) .SetTimeoutToFail(100) + .SetRetryLimit(2) .SetBranchHeaders(new Dictionary { { "bh1", "123" }, @@ -43,6 +44,7 @@ public async void Submit_Should_Succeed() Assert.NotNull(tb.CustomData); Assert.Equal(10, tb.RetryInterval); Assert.Equal(100, tb.TimeoutToFail); + Assert.Equal(2, tb.RetryLimit); Assert.True(true); }