Java源码示例:com.linecorp.armeria.client.ClientBuilder
示例1
/**
* Returns a newly-created {@link CentralDogma} instance.
*
* @throws UnknownHostException if failed to resolve the host names from the DNS servers
*/
public CentralDogma build() throws UnknownHostException {
final EndpointGroup endpointGroup = endpointGroup();
final String scheme = "none+" + (isUseTls() ? "https" : "http");
final ClientBuilder builder =
newClientBuilder(scheme, endpointGroup, cb -> cb.decorator(DecodingClient.newDecorator()), "/");
final EventLoopGroup executor = clientFactory().eventLoopGroup();
final int maxRetriesOnReplicationLag = maxNumRetriesOnReplicationLag();
final CentralDogma dogma = new ArmeriaCentralDogma(executor,
builder.build(WebClient.class),
accessToken());
if (maxRetriesOnReplicationLag <= 0) {
return dogma;
} else {
return new ReplicationLagTolerantCentralDogma(
executor, dogma, maxRetriesOnReplicationLag, retryIntervalOnReplicationLagMillis(),
() -> {
// FIXME(trustin): Note that this will always return `null` due to a known limitation
// in Armeria: https://github.com/line/armeria/issues/760
final ClientRequestContext ctx = ClientRequestContext.currentOrNull();
return ctx != null ? ctx.remoteAddress() : null;
});
}
}
示例2
public ClientBuilder newBuilder(String url) {
return Clients.builder("gproto+" + url)
.decorator(
client ->
new SimpleDecoratingHttpClient(client) {
@Override
public HttpResponse execute(ClientRequestContext ctx, HttpRequest req)
throws Exception {
// Many Google services do not support the standard application/grpc+proto
// header...
req =
req.withHeaders(
req.headers().toBuilder()
.set(HttpHeaderNames.CONTENT_TYPE, "application/grpc")
.build());
return delegate().execute(ctx, req);
}
})
.decorator(credentialsDecorator.newAccessTokenDecorator())
.decorator(BraveClient.newDecorator(tracing))
.decorator(MetricCollectingClient.newDecorator(MetricLabels.grpcRequestLabeler()))
.decorator(LoggingClient.builder().newDecorator());
}
示例3
/**
* Returns a newly created {@link ClientBuilder} configured with the specified {@code customizer}
* and then with the {@link ArmeriaClientConfigurator} specified with
* {@link #clientConfigurator(ArmeriaClientConfigurator)}.
*/
protected final ClientBuilder newClientBuilder(String scheme, EndpointGroup endpointGroup,
Consumer<ClientBuilder> customizer, String path) {
final ClientBuilder builder = Clients.builder(scheme, endpointGroup, path);
customizer.accept(builder);
clientConfigurator.configure(builder);
builder.factory(clientFactory());
return builder;
}
示例4
/**
* Configures the client using the specified {@link ClientBuilder}.
*/
void configure(ClientBuilder cb);