From 1c8f16fac0803aea71911b351aebf5cf8550b8aa Mon Sep 17 00:00:00 2001 From: Stanley Dimant Date: Sun, 9 Oct 2022 15:58:36 +0200 Subject: [PATCH] attempt with multiple grpc clients --- .../Services/GrpcClientIdentificationService.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/MareSynchronosServer/MareSynchronosServer/Services/GrpcClientIdentificationService.cs b/MareSynchronosServer/MareSynchronosServer/Services/GrpcClientIdentificationService.cs index 5f8675b..f944af2 100644 --- a/MareSynchronosServer/MareSynchronosServer/Services/GrpcClientIdentificationService.cs +++ b/MareSynchronosServer/MareSynchronosServer/Services/GrpcClientIdentificationService.cs @@ -17,6 +17,8 @@ public class GrpcClientIdentificationService : IHostedService private readonly string _shardName; private readonly ILogger _logger; private readonly IdentificationService.IdentificationServiceClient _grpcIdentClient; + private readonly IdentificationService.IdentificationServiceClient grpcIdentClientStreamOut; + private readonly IdentificationService.IdentificationServiceClient grpcIdentClientStreamIn; private readonly MareMetrics _metrics; protected readonly ConcurrentDictionary OnlineClients = new(StringComparer.Ordinal); private readonly ConcurrentDictionary RemoteCachedIdents = new(StringComparer.Ordinal); @@ -25,12 +27,16 @@ public class GrpcClientIdentificationService : IHostedService private CancellationTokenSource _streamCts = new(); private CancellationTokenSource _faultCheckCts = new(); - public GrpcClientIdentificationService(ILogger logger, IdentificationService.IdentificationServiceClient gprcIdentClient, MareMetrics metrics, IConfiguration configuration) + public GrpcClientIdentificationService(ILogger logger, IdentificationService.IdentificationServiceClient gprcIdentClient, + IdentificationService.IdentificationServiceClient gprcIdentClientStreamOut, + IdentificationService.IdentificationServiceClient gprcIdentClientStreamIn, MareMetrics metrics, IConfiguration configuration) { var config = configuration.GetSection("MareSynchronos"); _shardName = config.GetValue("ShardName", "Main"); _logger = logger; _grpcIdentClient = gprcIdentClient; + this.grpcIdentClientStreamOut = gprcIdentClientStreamOut; + this.grpcIdentClientStreamIn = gprcIdentClientStreamIn; _metrics = metrics; } @@ -184,7 +190,7 @@ public class GrpcClientIdentificationService : IHostedService { try { - using var stream = _grpcIdentClient.SendStreamIdentStatusChange(cancellationToken: cts); + using var stream = grpcIdentClientStreamOut.SendStreamIdentStatusChange(cancellationToken: cts); await stream.RequestStream.WriteAsync(new IdentChangeMessage() { Server = new ServerMessage() @@ -216,7 +222,7 @@ public class GrpcClientIdentificationService : IHostedService { try { - using var stream = _grpcIdentClient.ReceiveStreamIdentStatusChange(new ServerMessage() + using var stream = grpcIdentClientStreamIn.ReceiveStreamIdentStatusChange(new ServerMessage() { ServerId = _shardName, }); @@ -233,6 +239,7 @@ public class GrpcClientIdentificationService : IHostedService RemoteCachedIdents.TryRemove(cur.UidWithIdent.Uid.Uid, out _); } } + _logger.LogCritical("Receive Online Client Data Stream ended"); } catch (OperationCanceledException) { return; } catch