Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        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}");
        }