U
- the type of address before resolution (unresolved address)R
- the type of address after resolution (resolved address)public abstract class GrpcClientBuilder<U,R>
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
GrpcClientBuilder.MultiClientBuilder
An interface to create multiple gRPC clients sharing the
same underlying transport instance.
|
Constructor and Description |
---|
GrpcClientBuilder() |
Modifier and Type | Method and Description |
---|---|
abstract GrpcClientBuilder<U,R> |
appendConnectionFactoryFilter(ConnectionFactoryFilter<R,FilterableStreamingHttpConnection> factory)
Append the filter to the chain of filters used to decorate the
ConnectionFactory used by this
builder. |
abstract GrpcClientBuilder<U,R> |
appendConnectionFilter(java.util.function.Predicate<StreamingHttpRequest> predicate,
StreamingHttpConnectionFilterFactory factory)
Append the filter to the chain of filters used to decorate the
StreamingHttpConnection created by this
builder, for every request that passes the provided Predicate . |
abstract GrpcClientBuilder<U,R> |
appendConnectionFilter(StreamingHttpConnectionFilterFactory factory)
Append the filter to the chain of filters used to decorate the
StreamingHttpConnection created by this
builder. |
GrpcClientBuilder<U,R> |
appendHttpClientFilter(java.util.function.Predicate<StreamingHttpRequest> predicate,
StreamingHttpClientFilterFactory factory)
Append the filter to the chain of filters used to decorate the client created by this builder, for every request
that passes the provided
Predicate . |
GrpcClientBuilder<U,R> |
appendHttpClientFilter(StreamingHttpClientFilterFactory factory)
Append the filter to the chain of filters used to decorate the client created by this builder.
|
abstract GrpcClientBuilder<U,R> |
autoRetryStrategy(AutoRetryStrategyProvider autoRetryStrategyProvider)
Updates the automatic retry strategy for the clients generated by this builder.
|
abstract GrpcClientBuilder<U,R> |
bufferAllocator(BufferAllocator allocator)
Sets the
BufferAllocator for all clients created from this builder. |
<Client extends GrpcClient<?>,Filter extends FilterableClient,FilterableClient extends FilterableGrpcClient,FilterFactory extends GrpcClientFilterFactory<Filter,FilterableClient>> |
build(GrpcClientFactory<Client,?,Filter,FilterableClient,FilterFactory> clientFactory)
Builds a gRPC client.
|
<BlockingClient extends BlockingGrpcClient<?>,Filter extends FilterableClient,FilterableClient extends FilterableGrpcClient,FilterFactory extends GrpcClientFilterFactory<Filter,FilterableClient>> |
buildBlocking(GrpcClientFactory<?,BlockingClient,Filter,FilterableClient,FilterFactory> clientFactory)
Builds a blocking gRPC client.
|
GrpcClientBuilder.MultiClientBuilder |
buildMulti()
Returns a
GrpcClientBuilder.MultiClientBuilder to be used to create multiple clients sharing the same underlying transport
instance. |
protected abstract void |
doAppendHttpClientFilter(java.util.function.Predicate<StreamingHttpRequest> predicate,
StreamingHttpClientFilterFactory factory)
Append the filter to the chain of filters used to decorate the client created by this builder, for every request
that passes the provided
Predicate . |
protected abstract void |
doAppendHttpClientFilter(StreamingHttpClientFilterFactory factory)
Append the filter to the chain of filters used to decorate the client created by this builder.
|
abstract GrpcClientBuilder<U,R> |
enableWireLogging(java.lang.String loggerName)
Deprecated.
|
abstract GrpcClientBuilder<U,R> |
enableWireLogging(java.lang.String loggerName,
LogLevel logLevel,
java.util.function.BooleanSupplier logUserData)
Enables wire-logging for connections created by this builder.
|
abstract GrpcClientBuilder<U,R> |
executionStrategy(GrpcExecutionStrategy strategy)
Sets the
GrpcExecutionStrategy for all clients created from this builder. |
abstract GrpcClientBuilder<U,R> |
ioExecutor(IoExecutor ioExecutor)
Sets the
IoExecutor for all clients created from this builder. |
abstract GrpcClientBuilder<U,R> |
loadBalancerFactory(HttpLoadBalancerFactory<R> loadBalancerFactory)
Set a
HttpLoadBalancerFactory to create LoadBalancer instances. |
protected abstract GrpcClientCallFactory |
newGrpcClientCallFactory()
Create a new
GrpcClientCallFactory . |
abstract GrpcClientBuilder<U,R> |
protocols(HttpProtocolConfig... protocols)
Configurations of various underlying protocol versions.
|
abstract GrpcClientSecurityConfigurator<U,R> |
secure()
Initiate security configuration for this client.
|
abstract GrpcClientBuilder<U,R> |
serviceDiscoverer(ServiceDiscoverer<U,R,ServiceDiscovererEvent<R>> serviceDiscoverer)
Set a
ServiceDiscoverer to resolve addresses of remote servers to connect to. |
abstract <T> GrpcClientBuilder<U,R> |
socketOption(java.net.SocketOption<T> option,
T value)
Add a
SocketOption for all clients created by this builder. |
public abstract GrpcClientBuilder<U,R> ioExecutor(IoExecutor ioExecutor)
IoExecutor
for all clients created from this builder.ioExecutor
- IoExecutor
to use.this
.public abstract GrpcClientBuilder<U,R> bufferAllocator(BufferAllocator allocator)
BufferAllocator
for all clients created from this builder.allocator
- BufferAllocator
to use.this
.public abstract GrpcClientBuilder<U,R> executionStrategy(GrpcExecutionStrategy strategy)
GrpcExecutionStrategy
for all clients created from this builder.strategy
- GrpcExecutionStrategy
to use.this
.public abstract <T> GrpcClientBuilder<U,R> socketOption(java.net.SocketOption<T> option, T value)
SocketOption
for all clients created by this builder.T
- the type of the value.option
- the option to apply.value
- the value.this
.StandardSocketOptions
,
ServiceTalkSocketOptions
@Deprecated public abstract GrpcClientBuilder<U,R> enableWireLogging(java.lang.String loggerName)
loggerName
- The name of the logger to log wire events.this
.public abstract GrpcClientBuilder<U,R> enableWireLogging(java.lang.String loggerName, LogLevel logLevel, java.util.function.BooleanSupplier logUserData)
loggerName
- The name of the logger to log wire events.logLevel
- The level to log at.logUserData
- true
to include user data (e.g. data, headers, etc.). false
to exclude user
data and log only network events.this
.public abstract GrpcClientBuilder<U,R> protocols(HttpProtocolConfig... protocols)
Note: the order of specified protocols will reflect on priorities for ALPN in case the connections are secured.
protocols
- HttpProtocolConfig
for each protocol that should be supported.this
.public abstract GrpcClientBuilder<U,R> appendConnectionFactoryFilter(ConnectionFactoryFilter<R,FilterableStreamingHttpConnection> factory)
ConnectionFactory
used by this
builder.
Filtering allows you to wrap a ConnectionFactory
and modify behavior of
ConnectionFactory.newConnection(Object, TransportObserver)
.
Some potential candidates for filtering include logging and metrics.
The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder.append(filter1).append(filter2).append(filter3)Calling
ConnectionFactory
wrapped by this filter chain, the order of invocation of these filters will be:
filter1 => filter2 => filter3 => original connection factory
factory
- ConnectionFactoryFilter
to use.this
.public abstract GrpcClientBuilder<U,R> appendConnectionFilter(StreamingHttpConnectionFilterFactory factory)
StreamingHttpConnection
created by this
builder.
Filtering allows you to wrap a StreamingHttpConnection
and modify behavior during request/response
processing
Some potential candidates for filtering include logging, metrics, and decorating responses.
The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder.append(filter1).append(filter2).append(filter3)making a request to a connection wrapped by this filter chain the order of invocation of these filters will be:
filter1 => filter2 => filter3 => connection
factory
- StreamingHttpConnectionFilterFactory
to decorate a StreamingHttpConnection
for the
purpose of filtering.this
.public abstract GrpcClientBuilder<U,R> appendConnectionFilter(java.util.function.Predicate<StreamingHttpRequest> predicate, StreamingHttpConnectionFilterFactory factory)
StreamingHttpConnection
created by this
builder, for every request that passes the provided Predicate
.
Filtering allows you to wrap a StreamingHttpConnection
and modify behavior during request/response
processing
Some potential candidates for filtering include logging, metrics, and decorating responses.
The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder.append(filter1).append(filter2).append(filter3)making a request to a connection wrapped by this filter chain the order of invocation of these filters will be:
filter1 => filter2 => filter3 => connection
predicate
- the Predicate
to test if the filter must be applied.factory
- StreamingHttpConnectionFilterFactory
to decorate a StreamingHttpConnection
for the
purpose of filtering.this
.public abstract GrpcClientSecurityConfigurator<U,R> secure()
GrpcClientSecurityConfigurator.commit()
on the returned GrpcClientSecurityConfigurator
will
commit the configuration.GrpcClientSecurityConfigurator
to configure security for this client. It is
mandatory to call commit
after all configuration is
done.public abstract GrpcClientBuilder<U,R> autoRetryStrategy(AutoRetryStrategyProvider autoRetryStrategyProvider)
AutoRetryStrategyProvider
. These retries are not a
substitute for user level retries which are designed to infer retry decisions based on request/error information.
Typically such user level retries are done using filters but can also be done differently per request
(eg: by using Single.retry(BiIntPredicate)
).autoRetryStrategyProvider
- AutoRetryStrategyProvider
for the automatic retry strategy.this
public abstract GrpcClientBuilder<U,R> serviceDiscoverer(ServiceDiscoverer<U,R,ServiceDiscovererEvent<R>> serviceDiscoverer)
ServiceDiscoverer
to resolve addresses of remote servers to connect to.serviceDiscoverer
- The ServiceDiscoverer
to resolve addresses of remote servers to connect to.
Lifecycle of the provided ServiceDiscoverer
is managed externally and it should be
closed
after all built GrpcClient
s are closed and
this ServiceDiscoverer
is no longer needed.this
.public abstract GrpcClientBuilder<U,R> loadBalancerFactory(HttpLoadBalancerFactory<R> loadBalancerFactory)
HttpLoadBalancerFactory
to create LoadBalancer
instances.loadBalancerFactory
- HttpLoadBalancerFactory
to create LoadBalancer
instances.this
.public final GrpcClientBuilder<U,R> appendHttpClientFilter(StreamingHttpClientFilterFactory factory)
The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder.append(filter1).append(filter2).append(filter3)making a request to a client wrapped by this filter chain the order of invocation of these filters will be:
filter1 => filter2 => filter3 => client
factory
- StreamingHttpClientFilterFactory
to decorate a client for the purpose of filtering.this
public final GrpcClientBuilder<U,R> appendHttpClientFilter(java.util.function.Predicate<StreamingHttpRequest> predicate, StreamingHttpClientFilterFactory factory)
Predicate
.
The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder.append(filter1).append(filter2).append(filter3)making a request to a client wrapped by this filter chain the order of invocation of these filters will be:
filter1 => filter2 => filter3 => client
predicate
- the Predicate
to test if the filter must be applied.factory
- StreamingHttpClientFilterFactory
to decorate a client for the purpose of filtering.this
public final <Client extends GrpcClient<?>,Filter extends FilterableClient,FilterableClient extends FilterableGrpcClient,FilterFactory extends GrpcClientFilterFactory<Filter,FilterableClient>> Client build(GrpcClientFactory<Client,?,Filter,FilterableClient,FilterFactory> clientFactory)
Client
- gRPC service that any client built from
this factory represents.Filter
- Type for client filterFilterableClient
- Type of filterable client.FilterFactory
- Type of GrpcClientFilterFactory
clientFactory
- GrpcClientFactory
to use.public final <BlockingClient extends BlockingGrpcClient<?>,Filter extends FilterableClient,FilterableClient extends FilterableGrpcClient,FilterFactory extends GrpcClientFilterFactory<Filter,FilterableClient>> BlockingClient buildBlocking(GrpcClientFactory<?,BlockingClient,Filter,FilterableClient,FilterFactory> clientFactory)
BlockingClient
- Blocking gRPC service that any
client built from this builder represents.Filter
- Type for client filterFilterableClient
- Type of filterable client.FilterFactory
- Type of GrpcClientFilterFactory
clientFactory
- GrpcClientFactory
to use.public final GrpcClientBuilder.MultiClientBuilder buildMulti()
GrpcClientBuilder.MultiClientBuilder
to be used to create multiple clients sharing the same underlying transport
instance.protected abstract GrpcClientCallFactory newGrpcClientCallFactory()
GrpcClientCallFactory
.GrpcClientCallFactory
.protected abstract void doAppendHttpClientFilter(StreamingHttpClientFilterFactory factory)
The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder.append(filter1).append(filter2).append(filter3)making a request to a client wrapped by this filter chain the order of invocation of these filters will be:
filter1 => filter2 => filter3 => client
factory
- StreamingHttpClientFilterFactory
to decorate a client for the purpose of filtering.protected abstract void doAppendHttpClientFilter(java.util.function.Predicate<StreamingHttpRequest> predicate, StreamingHttpClientFilterFactory factory)
Predicate
.
The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder.append(filter1).append(filter2).append(filter3)making a request to a client wrapped by this filter chain the order of invocation of these filters will be:
filter1 => filter2 => filter3 => client
predicate
- the Predicate
to test if the filter must be applied.factory
- StreamingHttpClientFilterFactory
to decorate a client for the purpose of filtering.