add retry policy for grpc clients

This commit is contained in:
Stanley Dimant
2022-08-25 11:27:57 +02:00
parent 77e4602d2f
commit 2f1ef04f6a
3 changed files with 42 additions and 0 deletions

View File

@@ -15,6 +15,7 @@ using AspNetCoreRateLimit;
using MareSynchronosShared.Authentication; using MareSynchronosShared.Authentication;
using MareSynchronosShared.Data; using MareSynchronosShared.Data;
using MareSynchronosShared.Protos; using MareSynchronosShared.Protos;
using Grpc.Net.Client.Configuration;
namespace MareSynchronosServer namespace MareSynchronosServer
{ {
@@ -46,17 +47,38 @@ namespace MareSynchronosServer
var mareConfig = Configuration.GetRequiredSection("MareSynchronos"); var mareConfig = Configuration.GetRequiredSection("MareSynchronos");
var defaultMethodConfig = new MethodConfig
{
Names = { MethodName.Default },
RetryPolicy = new RetryPolicy
{
MaxAttempts = 100,
InitialBackoff = TimeSpan.FromSeconds(1),
MaxBackoff = TimeSpan.FromSeconds(5),
BackoffMultiplier = 1.5,
}
};
services.AddGrpcClient<AuthService.AuthServiceClient>(c => services.AddGrpcClient<AuthService.AuthServiceClient>(c =>
{ {
c.Address = new Uri(mareConfig.GetValue<string>("ServiceAddress")); c.Address = new Uri(mareConfig.GetValue<string>("ServiceAddress"));
}).ConfigureChannel(c =>
{
c.ServiceConfig = new ServiceConfig { MethodConfigs = { defaultMethodConfig } };
}); });
services.AddGrpcClient<MetricsService.MetricsServiceClient>(c => services.AddGrpcClient<MetricsService.MetricsServiceClient>(c =>
{ {
c.Address = new Uri(mareConfig.GetValue<string>("ServiceAddress")); c.Address = new Uri(mareConfig.GetValue<string>("ServiceAddress"));
}).ConfigureChannel(c =>
{
c.ServiceConfig = new ServiceConfig { MethodConfigs = { defaultMethodConfig } };
}); });
services.AddGrpcClient<FileService.FileServiceClient>(c => services.AddGrpcClient<FileService.FileServiceClient>(c =>
{ {
c.Address = new Uri(mareConfig.GetValue<string>("StaticFileServiceAddress")); c.Address = new Uri(mareConfig.GetValue<string>("StaticFileServiceAddress"));
}).ConfigureChannel(c =>
{
c.ServiceConfig = new ServiceConfig { MethodConfigs = { defaultMethodConfig } };
}); });
services.AddDbContextPool<MareDbContext>(options => services.AddDbContextPool<MareDbContext>(options =>

View File

@@ -484,6 +484,7 @@ public class DiscordBot : IHostedService
vanityUpdateCts = new(); vanityUpdateCts = new();
while (!vanityUpdateCts.IsCancellationRequested) while (!vanityUpdateCts.IsCancellationRequested)
{ {
logger.LogInformation($"Cleaning up Vanity UIDs");
var guild = discordClient.Guilds.FirstOrDefault(); var guild = discordClient.Guilds.FirstOrDefault();
if (guild == null) if (guild == null)
{ {

View File

@@ -1,3 +1,4 @@
using Grpc.Net.Client.Configuration;
using MareSynchronosShared.Authentication; using MareSynchronosShared.Authentication;
using MareSynchronosShared.Data; using MareSynchronosShared.Data;
using MareSynchronosShared.Protos; using MareSynchronosShared.Protos;
@@ -30,13 +31,31 @@ public class Startup
var mareSettings = Configuration.GetRequiredSection("MareSynchronos"); var mareSettings = Configuration.GetRequiredSection("MareSynchronos");
var defaultMethodConfig = new MethodConfig
{
Names = { MethodName.Default },
RetryPolicy = new RetryPolicy
{
MaxAttempts = 100,
InitialBackoff = TimeSpan.FromSeconds(1),
MaxBackoff = TimeSpan.FromSeconds(5),
BackoffMultiplier = 1.5,
}
};
services.AddGrpcClient<AuthService.AuthServiceClient>(c => services.AddGrpcClient<AuthService.AuthServiceClient>(c =>
{ {
c.Address = new Uri(mareSettings.GetValue<string>("ServiceAddress")); c.Address = new Uri(mareSettings.GetValue<string>("ServiceAddress"));
}).ConfigureChannel(c =>
{
c.ServiceConfig = new ServiceConfig { MethodConfigs = { defaultMethodConfig } };
}); });
services.AddGrpcClient<MetricsService.MetricsServiceClient>(c => services.AddGrpcClient<MetricsService.MetricsServiceClient>(c =>
{ {
c.Address = new Uri(mareSettings.GetValue<string>("ServiceAddress")); c.Address = new Uri(mareSettings.GetValue<string>("ServiceAddress"));
}).ConfigureChannel(c =>
{
c.ServiceConfig = new ServiceConfig { MethodConfigs = { defaultMethodConfig } };
}); });
services.AddDbContextPool<MareDbContext>(options => services.AddDbContextPool<MareDbContext>(options =>