public async Task HandleAsync(IncomingInvocationDescriptor info, ITransportChannel channel) { var invocation = _incomingInvocationFactory.CreateAsync <TRequest, TResponse>(info, channel); try { TRequest request = default; while (await invocation.In.WaitForNextSafeAsync().ConfigureAwait(false)) { while (invocation.In.TryReadSafe(out var item)) { request = item; } } var context = new MethodCallContext(info.Source.ApplicationId, info.Source.ConnectionId); await _handler(request, invocation.Out, context).ConfigureAwait(false); invocation.Out.TryComplete(); } catch (Exception ex) { invocation.Out.TryTerminate(ex); throw; } finally { await invocation.Completion.ConfigureAwait(false); } }
private Task HandleInvocationStartRequestAsync(IInvocationStartRequested request, ITransportChannel channel) { _log.Debug($"Handling invocation start request {request} on channel {channel.Id}"); if (!_options.ServicesDictionary.TryGetValue(request.ServiceId, out var providedService)) { throw new InvalidOperationException($"Service implementation not provided: {request.ServiceId}"); } if (!providedService.CallHandlers.TryGetValue(request.MethodId, out var callHandler)) { throw new InvalidOperationException($"Method implementation not provided: {request.ServiceId}.{request.MethodId}"); } var invocationInfo = new IncomingInvocationDescriptor( new InvocationMethodDescriptor( request.ServiceId, request.MethodId, request.ServiceAlias), new AppConnectionDescriptor( request.ConsumerConnectionId, request.ConsumerApplicationId, request.ConsumerApplicationInstanceId, _connection.TransportType)); return(callHandler.HandleAsync(invocationInfo, channel)); }
public async Task HandleAsync(IncomingInvocationDescriptor info, ITransportChannel channel) { var invocation = _incomingInvocationFactory.CreateAsync <TRequest, TResponse>(info, channel); var cancellation = new CancellationTokenSource(); invocation.Completion .ContinueWithSynchronously(_ => cancellation.Cancel(), CancellationToken.None) .IgnoreAwait(); try { await invocation.StartCompletion.ConfigureAwait(false); var context = new MethodCallContext( info.Source.ApplicationId, info.Source.ApplicationInstanceId, info.Source.ConnectionId, cancellation.Token); await HandleCoreAsync(invocation, context).ConfigureAwait(false); invocation.Out.TryComplete(); } catch (Exception ex) { invocation.Out.TryTerminate(ex); invocation.In.ConsumeBufferedItems(x => { }); throw; } finally { await invocation.Completion.ConfigureAwait(false); } }
private async Task HandleInvocationStartRequestAsync(IInvocationStartRequested request, ITransportChannel channel) { _log.Debug("Handling invocation start request: {0}", request); if (!_options.ServicesDictionary.TryGetValue((request.ServiceId, request.ServiceAlias), out var providedService)) { throw new InvalidOperationException($"Service implementation with alias {request.ServiceAlias} not provided: {request.ServiceId}"); } if (!providedService.CallHandlers.TryGetValue(request.MethodId, out var callHandler)) { throw new InvalidOperationException($"Method implementation with alias {request.ServiceAlias} not provided: {request.ServiceId}.{request.MethodId}"); } var invocationInfo = new IncomingInvocationDescriptor( new InvocationMethodDescriptor( request.ServiceId, request.MethodId, request.ServiceAlias), new InvocationSourceDescriptor( request.ConsumerApplicationId, request.ConsumerConnectionId)); await callHandler.HandleAsync(invocationInfo, channel).ConfigureAwait(false); }