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
6e9e80bc
authored
Mar 12, 2020
by
dingsongjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sagas client grpc 添加重试连接机制
parent
ac47a1a5
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
30 additions
and
34 deletions
samples/apis/SagasServer/Startup.cs
src/Pole.Sagas.Client/NotEndedSagasCompensateRetryBackgroundService.cs
src/Pole.Sagas.Client/PoleSagasOption.cs
src/Pole.Sagas.Server/PoleSagasServerApplicationBuilderExtensions.cs
src/Pole.Sagas.Server/PoleSagasServerServiceCollectionExtensions.cs
src/Pole.Sagas.Server/SagasBuffer.cs
samples/apis/SagasServer/Startup.cs
View file @
6e9e80bc
...
...
@@ -41,7 +41,7 @@ namespace SagasServer
{
app
.
UseDeveloperExceptionPage
();
}
app
.
UserPoleSagasServer
();
app
.
Run
(
async
(
context
)
=>
{
await
context
.
Response
.
WriteAsync
(
"Hello World!"
);
...
...
src/Pole.Sagas.Client/NotEndedSagasCompensateRetryBackgroundService.cs
View file @
6e9e80bc
...
...
@@ -35,8 +35,28 @@ namespace Pole.Sagas.Client
public
async
Task
StartAsync
(
CancellationToken
cancellationToken
)
{
while
(
true
)
{
try
{
await
GrpcGetSagasCore
(
cancellationToken
);
}
catch
(
Exception
ex
)
{
logger
.
LogError
(
ex
,
"Errors in GRPC"
);
}
finally
{
await
Task
.
Delay
(
options
.
GrpcConnectFailRetryIntervalSeconds
*
1000
);
}
}
}
private
async
Task
GrpcGetSagasCore
(
CancellationToken
cancellationToken
)
{
using
(
var
stream
=
sagaClient
.
GetSagas
(
new
Pole
.
Sagas
.
Server
.
Grpc
.
GetSagasRequest
{
Limit
=
options
.
PreSagasGrpcStreamingResponseLimitCount
,
ServiceName
=
options
.
ServiceName
}))
{
while
(
await
stream
.
ResponseStream
.
MoveNext
(
cancellationToken
))
{
if
(
stream
.
ResponseStream
.
Current
.
IsSuccess
)
...
...
@@ -73,39 +93,12 @@ namespace Pole.Sagas.Client
}
});
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
logger
.
LogError
(
ex
,
"Errors in NotEndedSagasCompensateRetryBackgroundService CompensateRetry"
);
}
}
}
//await foreach (var getSagasResponse in stream.ResponseStream.ReadAllAsync(cancellationToken))
//{
// if (getSagasResponse.IsSuccess)
// {
// var sagas = getSagasResponse.Sagas.Select(m =>
// {
// var result = new SagaEntity
// {
// Id = m.Id,
// };
// result.ActivityEntities = m.Activities.Select(n => new ActivityEntity
// {
// CompensateTimes = n.CompensateTimes,
// ExecuteTimes = n.ExecuteTimes,
// Id = n.Id,
// Name = n.Id,
// Order = n.Order,
// ParameterData = n.ParameterData.ToByteArray(),
// SagaId = n.SagaId,
// Status = n.Status
// }).ToList();
// return result;
// });
// }
//}
}
}
...
...
src/Pole.Sagas.Client/PoleSagasOption.cs
View file @
6e9e80bc
...
...
@@ -13,5 +13,6 @@ namespace Pole.Sagas.Client
public
int
CompeletedSagaExpiredAfterSeconds
{
get
;
set
;
}
=
60
*
10
;
public
int
SagasTimeOutSeconds
{
get
;
set
;
}
=
60
;
public
string
SagasServerHost
{
get
;
set
;
}
public
int
GrpcConnectFailRetryIntervalSeconds
{
get
;
set
;
}
=
10
;
}
}
src/Pole.Sagas.Server/PoleSagasServerApplicationBuilderExtensions.cs
View file @
6e9e80bc
...
...
@@ -4,11 +4,11 @@ using System;
using
System.Collections.Generic
;
using
System.Text
;
namespace
Pole.Sagas.Server
namespace
Microsoft.Extensions.Hosting
{
public
static
class
PoleSagasServerApplicationBuilderExtensions
{
public
static
IApplicationBuilder
UserPoleSagasServer
(
IApplicationBuilder
builder
)
public
static
IApplicationBuilder
UserPoleSagasServer
(
this
IApplicationBuilder
builder
)
{
builder
.
UseRouting
();
...
...
src/Pole.Sagas.Server/PoleSagasServerServiceCollectionExtensions.cs
View file @
6e9e80bc
...
...
@@ -11,16 +11,18 @@ namespace Microsoft.Extensions.DependencyInjection
{
public
static
class
PoleSagasServerServiceCollectionExtensions
{
public
static
StartupConfig
AddSagasServer
(
this
StartupConfig
startupConfig
,
Action
<
PoleSagasServerOption
>
config
=
null
)
{
public
static
StartupConfig
AddSagasServer
(
this
StartupConfig
startupConfig
,
Action
<
PoleSagasServerOption
>
config
=
null
)
{
Action
<
PoleSagasServerOption
>
defaultConfig
=
option
=>
{
};
var
finalConfig
=
config
??
defaultConfig
;
startupConfig
.
Services
.
AddGrpc
();
startupConfig
.
Services
.
Configure
(
finalConfig
);
startupConfig
.
Services
.
AddSingleton
<
IProcessor
,
NotEndedSagasFetchProcessor
>();
startupConfig
.
Services
.
AddSingleton
<
ISagasBuffer
,
SagasBuffer
>();
startupConfig
.
Services
.
AddSingleton
<
IProcessor
,
ExpiredSagasCollectorProcessor
>();
startupConfig
.
Services
.
AddHostedService
<
BackgroundServiceBasedProcessorServer
>();
return
startupConfig
;
}
}
...
...
src/Pole.Sagas.Server/SagasBuffer.cs
View file @
6e9e80bc
...
...
@@ -15,7 +15,7 @@ namespace Pole.Sagas.Server
private
readonly
SemaphoreSlim
semaphoreSlim
=
new
SemaphoreSlim
(
1
);
private
readonly
Dictionary
<
string
,
List
<
SagaEntity
>>
Sagas
=
new
Dictionary
<
string
,
List
<
SagaEntity
>>();
private
readonly
ILogger
logger
;
public
SagasBuffer
(
ILogger
logger
)
public
SagasBuffer
(
ILogger
<
SagasBuffer
>
logger
)
{
this
.
logger
=
logger
;
}
...
...
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