Skip to content

Commit 7b9deac

Browse files
authored
feat: saga support retrylimit (#56)
1 parent 6b3602f commit 7b9deac

File tree

8 files changed

+36
-1
lines changed

8 files changed

+36
-1
lines changed

build/version.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<PropertyGroup>
33

4-
<DtmCSharpVersion>1.2.0</DtmCSharpVersion>
4+
<DtmCSharpVersion>1.3.0</DtmCSharpVersion>
55

66
</PropertyGroup>
77
</Project>

src/DtmCommon/Imp/TransBase.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ public class TransBase
2626
[JsonPropertyName("branch_headers")]
2727
public Dictionary<string, string> BranchHeaders { get; set; }
2828

29+
[JsonPropertyName("retry_limit")]
30+
public long RetryLimit { get; set; }
31+
32+
[JsonPropertyName("retry_count")]
33+
public long RetryCount { get; set; }
34+
2935
/// <summary>
3036
/// use in MSG/SAGA
3137
/// </summary>

src/Dtmcli/Saga/Saga.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,16 @@ public Saga SetBranchHeaders(Dictionary<string, string> headers)
9696
this._transBase.BranchHeaders = headers;
9797
return this;
9898
}
99+
100+
/// <summary>
101+
/// Set global trans retry limit
102+
/// </summary>
103+
/// <param name="limit"></param>
104+
/// <returns></returns>
105+
public Saga SetRetryLimit(long limit)
106+
{
107+
this._transBase.RetryLimit = limit;
108+
return this;
109+
}
99110
}
100111
}

src/Dtmgrpc/DtmgRPCClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ private dtmgpb.DtmRequest BuildDtmRequest(TransBase transBase)
104104
WaitResult = transBase.WaitResult,
105105
TimeoutToFail = transBase.TimeoutToFail,
106106
RetryInterval = transBase.RetryInterval,
107+
RetryLimit = transBase.RetryLimit,
107108
};
108109

109110
if (transBase.BranchHeaders != null)

src/Dtmgrpc/Saga/SagaGrpc.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,16 @@ public SagaGrpc SetBranchHeaders(Dictionary<string, string> headers)
9999
this._transBase.BranchHeaders = headers;
100100
return this;
101101
}
102+
103+
/// <summary>
104+
/// Set global trans retry limit
105+
/// </summary>
106+
/// <param name="limit"></param>
107+
/// <returns></returns>
108+
public SagaGrpc SetRetryLimit(long limit)
109+
{
110+
this._transBase.RetryLimit = limit;
111+
return this;
112+
}
102113
}
103114
}

src/Dtmgrpc/dtmgpb/dtmgimp.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ message DtmTransOptions {
2121
int64 RetryInterval = 3;
2222
// repeated string PassthroughHeaders = 4;
2323
map<string, string> BranchHeaders = 5;
24+
int64 RequestTimeout = 6;
25+
int64 RetryLimit = 7;
2426
}
2527

2628
// DtmRequest request sent to dtm server

tests/Dtmcli.Tests/SagaTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public async void Submit_Should_Succeed()
4040
.EnableWaitResult()
4141
.SetRetryInterval(10)
4242
.SetTimeoutToFail(100)
43+
.SetRetryLimit(2)
4344
.SetBranchHeaders(new Dictionary<string, string>
4445
{
4546
{ "bh1", "123" },
@@ -123,6 +124,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
123124
Assert.Contains("bh2", transBase.BranchHeaders.Keys);
124125
Assert.Equal(4, transBase.Payloads.Count);
125126
Assert.Equal(4, transBase.Steps.Count);
127+
Assert.Equal(2, transBase.RetryLimit);
126128

127129
var content = new StringContent("{\"dtm_result\":\"SUCCESS\"}");
128130

tests/Dtmgrpc.Tests/SagaTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public async void Submit_Should_Succeed()
3131
.EnableConcurrent()
3232
.SetRetryInterval(10)
3333
.SetTimeoutToFail(100)
34+
.SetRetryLimit(2)
3435
.SetBranchHeaders(new Dictionary<string, string>
3536
{
3637
{ "bh1", "123" },
@@ -43,6 +44,7 @@ public async void Submit_Should_Succeed()
4344
Assert.NotNull(tb.CustomData);
4445
Assert.Equal(10, tb.RetryInterval);
4546
Assert.Equal(100, tb.TimeoutToFail);
47+
Assert.Equal(2, tb.RetryLimit);
4648

4749
Assert.True(true);
4850
}

0 commit comments

Comments
 (0)