jetcd is the official java client for etcd v3.
Note: jetcd is work-in-progress and may break backward compatibility.
Java 11 or above is required.
<dependency>
<groupId>io.etcd</groupId>
<artifactId>jetcd-core</artifactId>
<version>${jetcd-version}</version>
</dependency>Development snapshots are available in Sonatypes's snapshot repository.
dependencies {
implementation "io.etcd:jetcd-core:$jetcd-version"
}
// create client using endpointsClientclient = Client.builder().endpoints("http://etcd0:2379", "http://etcd1:2379", "http://etcd2:2379").build();// create client using target which enable using any name resolution mechanism provided// by grpc-java (i.e. dns:///foo.bar.com:2379)Clientclient = Client.builder().target("ip:///etcd0:2379,etcd1:2379,etcd2:2379").build();KVkvClient = client.getKVClient();
ByteSequencekey = ByteSequence.from("test_key".getBytes());
ByteSequencevalue = ByteSequence.from("test_value".getBytes());
// put the key-valuekvClient.put(key, value).get();
// get the CompletableFutureCompletableFuture<GetResponse> getFuture = kvClient.get(key);
// get the value from CompletableFutureGetResponseresponse = getFuture.get();
// delete the keykvClient.delete(key).get();To build one ssl secured client, refer to secured client config.
For full etcd v3 API, pleases refer to the official API documentation.
The jetcd-ctl is a standalone projects that show usage of jetcd.
The io.etcd:jetcd-test offers a convenient utility to programmatically start & stop an isolated etcd server. This can be very useful e.g. for integration testing, like so:
importio.etcd.jetcd.Client;
importio.etcd.jetcd.test.EtcdClusterExtension;
importorg.junit.jupiter.api.extension.RegisterExtension;
@RegisterExtensionpublicstaticfinalEtcdClusterExtensioncluster = EtcdClusterExtension.builder()
.withNodes(1)
.build();
Clientclient = Client.builder().endpoints(cluster.clientEndpoints()).build();This launcher uses the Testcontainers framework. For more info and prerequisites visit testcontainers.org.
The project follows Semantic Versioning.
The current major version is zero (0.y.z). Anything may change at any time. The public API should not be considered stable.
The project can be built with Gradle:
./gradlew compileJava
The project is tested against a three node etcd setup started with the Launcher (above) :
$ ./gradlew testIt recommends building the project before running tests so that you have artifacts locally. It will solve some problems if the latest snapshot hasn't been uploaded or network issues.
- Mailing list: etcd-dev
See CONTRIBUTING for details on submitting patches and the contribution workflow.
jetcd is under the Apache 2.0 license. See the LICENSE file for details.