Class GrpcClientBuilder
URI using the builder pattern.
Use the factory methods in GrpcClients if you do not have many options to override.-
Method Summary
Modifier and TypeMethodDescriptionaddHeader(CharSequence name, Object value) addHeaders(Iterable<? extends Map.Entry<? extends CharSequence, ?>> headers) auth(com.linecorp.armeria.common.auth.AuthToken token) auth(com.linecorp.armeria.common.auth.BasicToken token) auth(com.linecorp.armeria.common.auth.OAuth1aToken token) auth(com.linecorp.armeria.common.auth.OAuth2Token token) <T> TReturns a newly-created gRPC client which implements the specifiedclientType, based on the properties of this builder.callCredentials(CallCredentials callCredentials) Sets theCallCredentialsthat carries credential data that will be propagated to the server via request metadata.clientStubFactory(GrpcClientStubFactory clientStubFactory) Sets theGrpcClientStubFactorythat creates a gRPC client stub.compressor(Compressor compressor) Sets theCompressorto use when compressing messages.contextCustomizer(Consumer<? super com.linecorp.armeria.client.ClientRequestContext> contextCustomizer) decompressorRegistry(DecompressorRegistry registry) Sets theDecompressorRegistryto use when decompressing messages.decorator(com.linecorp.armeria.client.DecoratingHttpClientFunction decorator) decorator(Function<? super com.linecorp.armeria.client.HttpClient, ? extends com.linecorp.armeria.client.HttpClient> decorator) enableUnsafeWrapResponseBuffers(boolean enableUnsafeWrapResponseBuffers) (Advanced users only) Enables unsafe retention of response buffers.endpointRemapper(Function<? super com.linecorp.armeria.client.Endpoint, ? extends com.linecorp.armeria.client.endpoint.EndpointGroup> endpointRemapper) factory(com.linecorp.armeria.client.ClientFactory factory) followRedirects(com.linecorp.armeria.client.redirect.RedirectConfig redirectConfig) intercept(ClientInterceptor... interceptors) Adds theClientInterceptors to the gRPC client stub.intercept(Iterable<? extends ClientInterceptor> interceptors) Adds theClientInterceptors to the gRPC client stub.jsonMarshallerFactory(Function<? super ServiceDescriptor, ? extends GrpcJsonMarshaller> jsonMarshallerFactory) Sets the factory that creates aGrpcJsonMarshallerthat serializes and deserializes request or response messages to and from JSON depending on theSerializationFormat.maxRequestMessageLength(int maxRequestMessageLength) Sets the maximum size, in bytes, of messages sent in a request.maxResponseLength(long maxResponseLength) maxResponseMessageLength(int maxResponseMessageLength) Sets the maximum size, in bytes, of messages coming in a response.option(com.linecorp.armeria.client.ClientOption<T> option, T value) option(com.linecorp.armeria.client.ClientOptionValue<T> optionValue) options(com.linecorp.armeria.client.ClientOptions options) options(com.linecorp.armeria.client.ClientOptionValue<?>... options) Deprecated.pathPrefix(String prefix) Sets the context path for the gRPC endpoint.requestIdGenerator(Supplier<com.linecorp.armeria.common.RequestId> requestIdGenerator) responseTimeout(Duration responseTimeout) responseTimeoutMillis(long responseTimeoutMillis) rpcDecorator(com.linecorp.armeria.client.DecoratingRpcClientFunction decorator) Deprecated.Use eitherdecorator(DecoratingHttpClientFunction)orintercept(ClientInterceptor...)instead.rpcDecorator(Function<? super com.linecorp.armeria.client.RpcClient, ? extends com.linecorp.armeria.client.RpcClient> decorator) Deprecated.Use eitherdecorator(DecoratingHttpClientFunction)orintercept(ClientInterceptor...)instead.serializationFormat(com.linecorp.armeria.common.SerializationFormat serializationFormat) Sets the gRPCSerializationFormat.setHeader(CharSequence name, Object value) setHeaders(Iterable<? extends Map.Entry<? extends CharSequence, ?>> headers) successFunction(com.linecorp.armeria.common.SuccessFunction successFunction) writeTimeout(Duration writeTimeout) writeTimeoutMillis(long writeTimeoutMillis) Methods inherited from class com.linecorp.armeria.client.AbstractClientOptionsBuilder
buildOptions, buildOptions
-
Method Details
-
serializationFormat
public GrpcClientBuilder serializationFormat(com.linecorp.armeria.common.SerializationFormat serializationFormat) Sets the gRPCSerializationFormat. If not set, theScheme.serializationFormat()specified when creating this builder will be used by default.- See Also:
-
path
Deprecated.UsepathPrefix(String)instead.Sets the context path for the gRPC endpoint. This method will be useful if your gRPC service is bound to a context path. For example:// A gRPC service is bound to "/grpc/com.example.MyGrpcService/" Server.builder() .serviceUnder("/grpc", GrpcService.builder() .addService(new MyGrpcService()) .build()) .build(); // Prefix "/grpc" to the gRPC service path. GrpcClient.builder("https://api.example.com") .path("/grpc") .build(MyGrpcServiceGrpc.XXXStub.class) -
pathPrefix
Sets the context path for the gRPC endpoint. This method will be useful if your gRPC service is bound to a context path. For example:// A gRPC service is bound to "/grpc/com.example.MyGrpcService/" Server.builder() .serviceUnder("/grpc", GrpcService.builder() .addService(new MyGrpcService()) .build()) .build(); // Prefix "/grpc" to the gRPC service path. GrpcClient.builder("https://api.example.com") .pathPrefix("/grpc") .build(MyGrpcServiceGrpc.XXXStub.class) -
maxRequestMessageLength
Sets the maximum size, in bytes, of messages sent in a request. The default value is -1, which means unlimited. -
maxResponseMessageLength
Sets the maximum size, in bytes, of messages coming in a response. The default value is -1, which means 'useClientOptions.MAX_RESPONSE_LENGTH'. -
compressor
Sets theCompressorto use when compressing messages. If not set,Codec.Identity.NONEwill be used by default.Note that it is only safe to call this if the server supports the compression format chosen. There is no negotiation performed; if the server does not support the compression chosen, the call will fail.
-
decompressorRegistry
Sets theDecompressorRegistryto use when decompressing messages. If not set, will use the default, which supports gzip only. -
callCredentials
Sets theCallCredentialsthat carries credential data that will be propagated to the server via request metadata. -
enableUnsafeWrapResponseBuffers
@UnstableApi public GrpcClientBuilder enableUnsafeWrapResponseBuffers(boolean enableUnsafeWrapResponseBuffers) (Advanced users only) Enables unsafe retention of response buffers. Can improve performance when working with very large (i.e., several megabytes) payloads.DISCLAIMER: Do not use this if you don't know what you are doing. It is very easy to introduce memory leaks when using this method. You will probably spend much time debugging memory leaks during development if this is enabled. You will probably spend much time debugging memory leaks in production if this is enabled. You probably don't want to do this and should turn back now.
When enabled, the reference-counted buffer received from the server will be stored into
RequestContextinstead of being released. AllByteStringin a protobuf message will reference sections of this buffer instead of having their own copies. When done with a response message, callGrpcUnsafeBufferUtil.releaseBuffer(Object, RequestContext)with the message and the request's context to release the buffer. The message must be the same reference as what was passed to the client stub - a message with the same contents will not work. IfGrpcUnsafeBufferUtil.releaseBuffer(Object, RequestContext)is not called, the memory will be leaked.Note that this has no effect if the payloads are compressed or the
SerializationFormatisGrpcSerializationFormats.PROTO_WEB_TEXT. -
jsonMarshallerFactory
public GrpcClientBuilder jsonMarshallerFactory(Function<? super ServiceDescriptor, ? extends GrpcJsonMarshaller> jsonMarshallerFactory) Sets the factory that creates aGrpcJsonMarshallerthat serializes and deserializes request or response messages to and from JSON depending on theSerializationFormat. The returnedGrpcJsonMarshallerfrom the factory replaces the built-inGrpcJsonMarshaller.This is commonly used to:
- Switch from the default of using lowerCamelCase for field names to using the field name from
the proto definition, by setting
MessageMarshaller.Builder.preservingProtoFieldNames(boolean)viaGrpcJsonMarshallerBuilder.jsonMarshallerCustomizer(Consumer).GrpcClients.builder(grpcServerUri) .jsonMarshallerFactory(serviceDescriptor -> { return GrpcJsonMarshaller.builder() .jsonMarshallerCustomizer(builder -> { builder.preservingProtoFieldNames(true); }) .build(serviceDescriptor); }) .build(); - Set a customer marshaller for non-
Messagetypes such asscalapb.GeneratedMessagewithcom.linecorp.armeria.common.scalapb.ScalaPbJsonMarshallerfor Scala.GrpcClients.builder(grpcServerUri) .jsonMarshallerFactory(_ => ScalaPbJsonMarshaller()) .build()
- Switch from the default of using lowerCamelCase for field names to using the field name from
the proto definition, by setting
-
clientStubFactory
Sets theGrpcClientStubFactorythat creates a gRPC client stub. If not specified, Armeria provides built-in factories for the following gRPC client stubs: -
intercept
Adds theClientInterceptors to the gRPC client stub. The specified interceptor(s) is/are executed in reverse order. -
intercept
Adds theClientInterceptors to the gRPC client stub. The specified interceptor(s) is/are executed in reverse order. -
rpcDecorator
@Deprecated public GrpcClientBuilder rpcDecorator(Function<? super com.linecorp.armeria.client.RpcClient, ? extends com.linecorp.armeria.client.RpcClient> decorator) Deprecated.Use eitherdecorator(DecoratingHttpClientFunction)orintercept(ClientInterceptor...)instead.Unsupported operation.rpcDecoratoronly supports Thrift.- Overrides:
rpcDecoratorin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
rpcDecorator
@Deprecated public GrpcClientBuilder rpcDecorator(com.linecorp.armeria.client.DecoratingRpcClientFunction decorator) Deprecated.Use eitherdecorator(DecoratingHttpClientFunction)orintercept(ClientInterceptor...)instead.Unsupported operation.rpcDecoratoronly supports Thrift.- Overrides:
rpcDecoratorin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
build
Returns a newly-created gRPC client which implements the specifiedclientType, based on the properties of this builder. -
options
- Overrides:
optionsin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
options
- Overrides:
optionsin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
options
public GrpcClientBuilder options(Iterable<com.linecorp.armeria.client.ClientOptionValue<?>> options) - Overrides:
optionsin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
option
- Overrides:
optionin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
option
- Overrides:
optionin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
factory
- Overrides:
factoryin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
writeTimeout
- Overrides:
writeTimeoutin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
writeTimeoutMillis
- Overrides:
writeTimeoutMillisin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
responseTimeout
- Overrides:
responseTimeoutin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
responseTimeoutMillis
- Overrides:
responseTimeoutMillisin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
maxResponseLength
- Overrides:
maxResponseLengthin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
requestIdGenerator
public GrpcClientBuilder requestIdGenerator(Supplier<com.linecorp.armeria.common.RequestId> requestIdGenerator) - Overrides:
requestIdGeneratorin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
successFunction
public GrpcClientBuilder successFunction(com.linecorp.armeria.common.SuccessFunction successFunction) - Overrides:
successFunctionin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
endpointRemapper
public GrpcClientBuilder endpointRemapper(Function<? super com.linecorp.armeria.client.Endpoint, ? extends com.linecorp.armeria.client.endpoint.EndpointGroup> endpointRemapper) - Overrides:
endpointRemapperin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
decorator
public GrpcClientBuilder decorator(Function<? super com.linecorp.armeria.client.HttpClient, ? extends com.linecorp.armeria.client.HttpClient> decorator) - Overrides:
decoratorin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
decorator
public GrpcClientBuilder decorator(com.linecorp.armeria.client.DecoratingHttpClientFunction decorator) - Overrides:
decoratorin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
clearDecorators
- Overrides:
clearDecoratorsin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
addHeader
- Overrides:
addHeaderin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
addHeaders
public GrpcClientBuilder addHeaders(Iterable<? extends Map.Entry<? extends CharSequence, ?>> headers) - Overrides:
addHeadersin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
setHeader
- Overrides:
setHeaderin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
setHeaders
public GrpcClientBuilder setHeaders(Iterable<? extends Map.Entry<? extends CharSequence, ?>> headers) - Overrides:
setHeadersin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
auth
- Overrides:
authin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
auth
- Overrides:
authin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
auth
- Overrides:
authin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
auth
- Overrides:
authin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
followRedirects
- Overrides:
followRedirectsin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
followRedirects
public GrpcClientBuilder followRedirects(com.linecorp.armeria.client.redirect.RedirectConfig redirectConfig) - Overrides:
followRedirectsin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
contextCustomizer
public GrpcClientBuilder contextCustomizer(Consumer<? super com.linecorp.armeria.client.ClientRequestContext> contextCustomizer) - Overrides:
contextCustomizerin classcom.linecorp.armeria.client.AbstractClientOptionsBuilder
-
pathPrefix(String)instead.