This section will illustrate how to set up a demo Java application using Goblin.
Use the latest release of goblin-java-client.
<dependency>
<groupId>com.ebay.magellan</groupId>
<artifactId>goblin-java-client</artifactId>
<version>3.5.0-RELEASE</version>
</dependency> RaftClusterClientConfig config = RaftClusterClientConfig.builder()
.clusterInfo(clusterAddresses)
.timeoutInMilliSeconds(timeoutInMilliSeconds)
.stubTimeoutInMilliSeconds(stubTimeoutInMilliSeconds)
.tlsEnabled(grpcTlsEnable)
.clusterInfoResolver(new TessClusterInfoResolver())
.poolType(poolType)
.build();| Key | Value |
|---|---|
| timeoutInMilliSeconds | The overall timeout (in milliseconds) of a RaftClusterClient method call RaftClusterClient ensures that a method call throws RaftInvokeTimeoutException exception shortly after timeoutInMilliSeconds milliseconds when the method was not completed. Default value: 10000 |
| stubTimeoutInMilliSeconds | The gPRC timeout (in milliseconds) of a single API call between the client and Goblin server. Change this value only when the connection between the server and client is very unstable. In most cases, set #timeoutInMilliSeconds# for the overall timeout configuration. Default value: 500 |
| clusterInfo | Goblin servers' addresses. The format is: "<node_id_1>@:,<node_id_2>@:,<node_id_3>@:,..." e.g. experimental dev goblin "1@om-expt-dev-fss-1.goblin-dev.stratus.qa.ebay.com:50055,2@om-expt-dev-fss-2.goblin-dev.stratus.qa.ebay.com:50055,3@om-expt-dev-fss-3.goblin-dev.stratus.qa.ebay.com:50055,4@om-expt-dev-fss-4.goblin-dev.stratus.qa.ebay.com:50055,5@om-expt-dev-fss-5.goblin-dev.stratus.qa.ebay.com:50055" |
| clusterInfoResolver | The implementation of ClusterInfoResolver interface. It is used to resolve dns of the clusterInfo to a list of Goblin servers' ip addresses. |
| tlsEnabled | true: enable TLS in the connection between the client and Goblin server. false: disable TLS in the connection between the client and Goblin server. |
| sslContext | io.grpc.netty.shaded.io.netty.handler.ssl.SslContext object for TLS connection. Mandatory if tlsEnabled is true. |
| poolType | The configuration of read mode.LeaderOnly: always found leader to connect.RoundRobin: round robin to pick a client.InSyncReplica: round robin to pick a client but it should be closed to leader enough. In-sync means the gap of the committed index between follower and leader is less than a pre-defined threshold. If you want strong consistency read, use LeaderOnly Default value: LeaderOnly |
| ISRValidMinGap | The threshold of the gap of committed index between follower and leader. If the real gap is less than this threshold, the follower is considered as ISR follower, and can serve read traffic, otherwise the follower can't serve read traffic. It takes effective only if poolType is configured as InSyncReplica.Default value: 100 |
| ISRRefreshTime | Time interval to refresh ISR list. Default value: 120000 (2min) |
| ISRLeaseTime | Lease for an ISR List becomes invalid. Default value: 600000 (10min) |
| intervalPerRound | The backoff delay between gRPC call retry attempts Default value: 5(ms) |
GoblinClient is thread safe. Only one GoblinClient is needed for all API calls with a specific Goblin cluster. For the complete documents of Goblin APIs, please refer to Client API Reference for Java
RaftClusterClientConfig config = RaftClusterClientConfig.builder()
.clusterInfo("1@om-expt-dev-fss-1.goblin-dev.stratus.qa.ebay.com:50055,2@om-expt-dev-fss-2.goblin-dev.stratus.qa.ebay.com:50055,3@om-expt-dev-fss-3.goblin-dev.stratus.qa.ebay.com:50055,4@om-expt-dev-fss-4.goblin-dev.stratus.qa.ebay.com:50055,5@om-expt-dev-fss-5.goblin-dev.stratus.qa.ebay.com:50055")
.timeoutInMilliSeconds(10000L)
.tlsEnabled(false)
.poolType(PoolType.LeaderOnly)
.build();
// build a Goblin client
GoblinClient goblinClient = null;
try {
// build the client
goblinClient = builder.build();
} catch (GoblinException e) {
// handle the exception here.
} finally {
if(goblinClient != null) {
goblinClient.close();
}
}GoblinClient implements the AutoCloseable interface. So the above sample could also be
try (GoblinClient client = builder.build()) {
// call APIs
// ... ...
} catch (GoblinException e) {
// handle the exception here.
}