public GrpcWorker(IFunctionsApplication application, FunctionRpcClient rpcClient, GrpcHostChannel outputChannel, IInvocationFeaturesFactory invocationFeaturesFactory, IOutputBindingsInfoProvider outputBindingsInfoProvider, IMethodInfoLocator methodInfoLocator, IOptions <GrpcWorkerStartupOptions> startupOptions, IOptions <WorkerOptions> workerOptions) { if (outputChannel == null) { throw new ArgumentNullException(nameof(outputChannel)); } _outputReader = outputChannel.Channel.Reader; _outputWriter = outputChannel.Channel.Writer; _application = application ?? throw new ArgumentNullException(nameof(application)); _rpcClient = rpcClient ?? throw new ArgumentNullException(nameof(rpcClient)); _invocationFeaturesFactory = invocationFeaturesFactory ?? throw new ArgumentNullException(nameof(invocationFeaturesFactory)); _outputBindingsInfoProvider = outputBindingsInfoProvider ?? throw new ArgumentNullException(nameof(outputBindingsInfoProvider)); _methodInfoLocator = methodInfoLocator ?? throw new ArgumentNullException(nameof(methodInfoLocator)); _startupOptions = startupOptions ?? throw new ArgumentNullException(nameof(startupOptions)); _serializer = workerOptions.Value.Serializer ?? throw new InvalidOperationException(nameof(workerOptions.Value.Serializer)); }
internal static async Task <InvocationResponse> InvocationRequestHandlerAsync(InvocationRequest request, IFunctionsApplication application, IInvocationFeaturesFactory invocationFeaturesFactory, ObjectSerializer serializer, IOutputBindingsInfoProvider outputBindingsInfoProvider) { FunctionContext? context = null; FunctionInvocation?invocation = null; InvocationResponse response = new() { InvocationId = request.InvocationId }; try { invocation = new GrpcFunctionInvocation(request); IInvocationFeatures invocationFeatures = invocationFeaturesFactory.Create(); invocationFeatures.Set <FunctionInvocation>(invocation); context = application.CreateContext(invocationFeatures); invocationFeatures.Set <IFunctionBindingsFeature>(new GrpcFunctionBindingsFeature(context, request, outputBindingsInfoProvider)); await application.InvokeFunctionAsync(context); var functionBindings = context.GetBindings(); foreach (var binding in functionBindings.OutputBindingData) { var parameterBinding = new ParameterBinding { Name = binding.Key }; if (binding.Value is not null) { parameterBinding.Data = await binding.Value.ToRpcAsync(serializer); } response.OutputData.Add(parameterBinding); } if (functionBindings.InvocationResult != null) { TypedData?returnVal = await functionBindings.InvocationResult.ToRpcAsync(serializer); response.ReturnValue = returnVal; } response.Result = new StatusResult { Status = StatusResult.Types.Status.Success }; } catch (Exception ex) { response.Result = new StatusResult { Exception = ex.ToRpcException(), Status = StatusResult.Types.Status.Failure }; } finally { (context as IDisposable)?.Dispose(); } return(response); }
public GrpcFunctionBindingsFeature(FunctionContext context, InvocationRequest invocationRequest, IOutputBindingsInfoProvider outputBindingsInfoProvider) { _context = context ?? throw new ArgumentNullException(nameof(context)); _invocationRequest = invocationRequest ?? throw new ArgumentNullException(nameof(invocationRequest)); _outputBindingsInfoProvider = outputBindingsInfoProvider ?? throw new ArgumentNullException(nameof(outputBindingsInfoProvider)); }