examples: Modify the way of getHedgingServiceConfig in io.grpc.examples.hedging.HedgingHelloWorldClient (#7700)

This commit is contained in:
赵延 2020-12-10 08:21:23 +08:00 committed by GitHub
parent 26e88d9326
commit f5865d5bf2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 9 deletions

View File

@ -51,6 +51,12 @@ public class HedgingHelloWorldClient {
/** Construct client connecting to HelloWorld server at {@code host:port}. */ /** Construct client connecting to HelloWorld server at {@code host:port}. */
public HedgingHelloWorldClient(String host, int port, boolean hedging) { public HedgingHelloWorldClient(String host, int port, boolean hedging) {
ManagedChannelBuilder<?> channelBuilder = ManagedChannelBuilder.forAddress(host, port)
// Channels are secure by default (via SSL/TLS). For the example we disable TLS to avoid
// needing certificates.
.usePlaintext();
if (hedging) {
Map<String, ?> hedgingServiceConfig = Map<String, ?> hedgingServiceConfig =
new Gson() new Gson()
.fromJson( .fromJson(
@ -60,12 +66,6 @@ public class HedgingHelloWorldClient {
"hedging_service_config.json"), "hedging_service_config.json"),
UTF_8)), UTF_8)),
Map.class); Map.class);
ManagedChannelBuilder<?> channelBuilder = ManagedChannelBuilder.forAddress(host, port)
// Channels are secure by default (via SSL/TLS). For the example we disable TLS to avoid
// needing certificates.
.usePlaintext();
if (hedging) {
channelBuilder.defaultServiceConfig(hedgingServiceConfig).enableRetry(); channelBuilder.defaultServiceConfig(hedgingServiceConfig).enableRetry();
} }
channel = channelBuilder.build(); channel = channelBuilder.build();