public async Task ReceiveAsync(IContext context) { switch (context.Message) { case Started _: var connectionHeaders = new Metadata() { { "clientid", clientId } }; _logger.LogDebug("Connecting Streams"); var client = new ClientRemoting.ClientRemotingClient(channel); _clientStreams = client.ConnectClient(connectionHeaders); //, DateTime.UtcNow.Add(connectionTimeout)); //Assign a reader to the connection _endpointReader = context.Spawn(Props.FromProducer(() => new ClientEndpointReader(_clientStreams.ResponseStream))); //Start this in a new process so the loop is not affected by parent processes shuttting down (eg. Orleans) context.SetReceiveTimeout(connectionTimeout); break; case EndpointConnectedEvent _: context.Forward(context.Parent); break; case RemoteDeliver rd: var batch = rd.getMessageBatch(); _logger.LogDebug($"Sending RemoteDeliver message {rd.Message.GetType()} to {rd.Target.Id} address {rd.Target.Address} from {rd.Sender}"); var clientBatch = new ClientMessageBatch() { Address = rd.Target.Address, Batch = batch }; try { await _clientStreams.RequestStream.WriteAsync(clientBatch); } catch (Exception ex) { context.Stash(); throw ex; } _logger.LogDebug($"Sent RemoteDeliver message {rd.Message.GetType()} to {rd.Target.Id} address {rd.Target.Address} from {rd.Sender}"); break; } }
private void Send(object envelope) { var(message, sender, header) = MessageEnvelope.Unwrap(envelope); _logger.LogDebug($"Sending Client Message {message.GetType()} to {_clientTargetPID} via {_endpointWriterPID}"); var env = new RemoteDeliver(header, message, _clientTargetPID, sender, Serialization.DefaultSerializerId); var messageBatch = new ClientMessageBatch { Address = _endpointWriterPID.Address, Batch = env.getMessageBatch() }; RootContext.Empty.Send(_endpointWriterPID, messageBatch); }