private Task StartedAsync() { _logger.LogDebug($"Connecting to address {_address}"); _channel = new Channel(_address, _channelCredentials, _channelOptions); _client = new Remoting.RemotingClient(_channel); _stream = _client.Receive(_callOptions); Task.Factory.StartNew(async() => { try { await _stream.ResponseStream.ForEachAsync(i => Actor.Done); } catch (Exception x) { _logger.LogError($"Lost connection to address {_address}, reason {x.Message}"); var terminated = new EndpointTerminatedEvent { Address = _address }; Actor.EventStream.Publish(terminated); } }); _streamWriter = _stream.RequestStream; _logger.LogDebug($"Connected to address {_address}"); return(Actor.Done); }
private Task StartedAsync() { Console.WriteLine("[REMOTING] Started EndpointWriter for address {0}", _address); Console.WriteLine("[REMOTING] EndpointWriter connecting to address {0}", _address); _channel = new Channel(_address, ChannelCredentials.Insecure); _client = new Remoting.RemotingClient(_channel); _stream = _client.Receive(); Task.Factory.StartNew(async() => { try { await _stream.ResponseStream.ForEachAsync(i => Actor.Done); } catch (Exception x) { Console.WriteLine( $"[REMOTING] EndpointWriter lost connection to address {_address}, reason {x.Message}"); var terminated = new EndpointTerminatedEvent { Address = _address }; Actor.EventStream.Publish(terminated); } }); _streamWriter = _stream.RequestStream; Console.WriteLine("[REMOTING] EndpointWriter connected to address {0}", _address); return(Actor.Done); }
private static void OnEndpointTerminated(EndpointTerminatedEvent msg) { if (Connections.TryRemove(msg.Address, out var v)) { var endpoint = v.Value; RootContext.Empty.Send(endpoint.Watcher, msg); RootContext.Empty.Send(endpoint.Writer, msg); } }
private static void OnEndpointTerminated(EndpointTerminatedEvent msg) { if (_connections.TryRemove(msg.Address, out var v)) { var endpoint = v.Value; endpoint.Watcher.Tell(msg); endpoint.Watcher.Stop(); endpoint.Writer.Stop(); } }
private async Task StartedAsync() { _logger.LogDebug($"Connecting to address {_address}"); _channel = new Channel(_address, _channelCredentials, _channelOptions); _client = new Remoting.RemotingClient(_channel); try { var res = await _client.ConnectAsync(new ConnectRequest()); _serializerId = res.DefaultSerializerId; _stream = _client.Receive(_callOptions); _streamWriter = _stream.RequestStream; } catch (Exception ex) { _logger.LogError($"GRPC Failed to connect to address {_address}\n{ex}"); //Wait for 2 seconds to restart and retry //Replace with Exponential Backoff await Task.Delay(2000); throw; } var _ = Task.Factory.StartNew(async() => { try { await _stream.ResponseStream.ForEachAsync(i => Actor.Done).ConfigureAwait(false); } catch (Exception x) { _logger.LogError($"Lost connection to address {_address}, reason {x.Message}"); var terminated = new EndpointTerminatedEvent { Address = _address }; Actor.EventStream.Publish(terminated); } }); var connected = new EndpointConnectedEvent { Address = _address }; Actor.EventStream.Publish(connected); _logger.LogDebug($"Connected to address {_address}"); }