private Task HandleInitAsync(OperationMessage message) { _logger.LogInformation("Handle init"); return(TransportWriter.SendAsync(new OperationMessage { Type = MessageType.GQL_CONNECTION_ACK })); }
public MessageHandlingContext(IServerOperations server, OperationMessage message) { _server = server; Reader = server.TransportReader; Writer = server.TransportWriter; Subscriptions = server.Subscriptions; Message = message; }
private Task HandleStartAsync(OperationMessage message) { _logger.LogInformation("Handle start: {id}", message.Id); var payload = message.Payload.ToObject <OperationMessagePayload>(); if (payload == null) { throw new InvalidOperationException($"Could not get OperationMessagePayload from message.Payload"); } return(Subscriptions.SubscribeOrExecuteAsync( message.Id, payload, TransportWriter)); }
private async Task HandleMessageAsync(OperationMessage message) { _logger.LogDebug("Handling message: {id} of type: {type}", message.Id, message.Type); using (var context = await BuildMessageHandlingContext(message)) { await OnBeforeHandleAsync(context); if (context.Terminated) { return; } await OnHandleAsync(context); await OnAfterHandleAsync(context); } }
private Task HandleUnknownAsync(OperationMessage message) { _logger.LogError($"Unexpected message type: {message.Type}"); return(TransportWriter.SendAsync(new OperationMessage { Type = MessageType.GQL_CONNECTION_ERROR, Id = message.Id, Payload = JObject.FromObject(new { message.Id, Errors = new ExecutionErrors { new ExecutionError($"Unexpected message type {message.Type}") } }) })); }
private async Task HandleMessageAsync(OperationMessage message) { _logger.LogDebug("Handling message: {id} of type: {type}", message.Id, message.Type); await OnBeforeHandleAsync(message); //todo(pekka): should this be changed into message listener? switch (message.Type) { case MessageType.GQL_CONNECTION_INIT: await HandleInitAsync(message); break; case MessageType.GQL_START: await HandleStartAsync(message); break; case MessageType.GQL_STOP: await HandleStopAsync(message); break; case MessageType.GQL_CONNECTION_TERMINATE: await HandleTerminateAsync(message); break; default: await HandleUnknownAsync(message); break; } await OnAfterHandleAsync(message); }
private Task <MessageHandlingContext> BuildMessageHandlingContext(OperationMessage message) { return(Task.FromResult(new MessageHandlingContext(this, message))); }
public Task OnAfterHandleAsync(IReaderPipeline reader, IWriterPipeline writer, OperationMessage message) { return(Task.CompletedTask); }
public Task OnBeforeHandleAsync(IReaderPipeline reader, IWriterPipeline writer, OperationMessage message) { _logger.LogDebug("Received message: {message}", message); return(Task.CompletedTask); }
private Task HandleStopAsync(OperationMessage message) { _logger.LogInformation("Handle stop: {id}", message.Id); return(Subscriptions.UnsubscribeAsync(message.Id)); }
private async Task HandleTerminateAsync(OperationMessage message) { _logger.LogInformation("Handle terminate"); await Terminate(); }