/// <summary> /// Builds an <see cref="ApiCall"/> given suitable underlying async and sync calls. /// </summary> /// <typeparam name="TRequest">Request type, which must be a protobuf message.</typeparam> /// <typeparam name="TResponse">Response type, which must be a protobuf message.</typeparam> /// <param name="asyncGrpcCall">The underlying synchronous gRPC call.</param> /// <param name="syncGrpcCall">The underlying asynchronous gRPC call.</param> /// <param name="perMethodCallSettings">The default method call settings.</param> /// <returns>An API call to proxy to the RPC calls</returns> public ApiCall <TRequest, TResponse> BuildApiCall <TRequest, TResponse>( Func <TRequest, CallOptions, AsyncUnaryCall <TResponse> > asyncGrpcCall, Func <TRequest, CallOptions, TResponse> syncGrpcCall, CallSettings perMethodCallSettings) where TRequest : class, IMessage <TRequest> where TResponse : class, IMessage <TResponse> { CallSettings baseCallSettings = _clientCallSettings.MergedWith(perMethodCallSettings); // These operations are applied in reverse order. // I.e. Version header is added first, then retry is performed. return(ApiCall.Create(asyncGrpcCall, syncGrpcCall, baseCallSettings, Clock) .WithRetry(Clock, Scheduler) .WithMergedBaseCallSettings(_versionCallSettings)); }
/// <summary> /// Returns a new <see cref="CallSettings"/> with the specified header, /// merged with the (optional) original settings specified by <paramref name="settings"/>. /// </summary> /// <param name="settings">Original settings. May be null, in which case the returned settings /// will only contain the header.</param> /// <param name="name">Header name. Must not be null.</param> /// <param name="value">Header value. Must not be null.</param> /// <returns>A new set of call settings including the specified header.</returns> public static CallSettings WithHeader(this CallSettings settings, string name, string value) => settings.MergedWith(CallSettings.FromHeader(name, value));
/// <summary> /// /// </summary> /// <param name="settings"></param> /// <param name="handler"></param> /// <returns></returns> public static CallSettings WithTrailingMetadataHandler(this CallSettings settings, Action <Metadata> handler) => settings.MergedWith(CallSettings.FromTrailingMetadataHandler(handler));
/// <summary> /// Returns a new <see cref="CallSettings"/> with the specified cancellation token, /// merged with the (optional) original settings specified by <paramref name="settings"/>. /// </summary> /// <param name="settings">Original settings. May be null, in which case the returned settings /// will only contain the cancellation token.</param> /// <param name="cancellationToken">Cancellation token for the new call settings.</param> /// <returns>A new set of call settings.</returns> public static CallSettings WithCancellationToken( this CallSettings settings, CancellationToken cancellationToken) => settings.MergedWith(CallSettings.FromCancellationToken(cancellationToken));
/// <summary> /// /// </summary> /// <param name="handler"></param> /// <param name="settings"></param> /// <returns></returns> public static CallSettings WithResponseMetadataHandler(this CallSettings settings, Action <Metadata> handler) => settings.MergedWith(CallSettings.FromResponseMetadataHandler(handler));