etcd Java client

Simple Java client to interact with CoreOS's etcd

License

License

Categories

Categories

CLI User Interface
GroupId

GroupId

com.github.mlaccetti
ArtifactId

ArtifactId

etcd-client
Last Version

Last Version

0.1.3
Release Date

Release Date

Type

Type

jar
Description

Description

etcd Java client
Simple Java client to interact with CoreOS's etcd
Project URL

Project URL

https://github.com/mlaccetti/jetcd
Source Code Management

Source Code Management

https://github.com/mlaccetti/jetcd

Download etcd-client

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.mlaccetti/etcd-client/ -->
<dependency>
    <groupId>com.github.mlaccetti</groupId>
    <artifactId>etcd-client</artifactId>
    <version>0.1.3</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.mlaccetti/etcd-client/
implementation 'com.github.mlaccetti:etcd-client:0.1.3'
// https://jarcasting.com/artifacts/com.github.mlaccetti/etcd-client/
implementation ("com.github.mlaccetti:etcd-client:0.1.3")
'com.github.mlaccetti:etcd-client:jar:0.1.3'
<dependency org="com.github.mlaccetti" name="etcd-client" rev="0.1.3">
  <artifact name="etcd-client" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.mlaccetti', module='etcd-client', version='0.1.3')
)
libraryDependencies += "com.github.mlaccetti" % "etcd-client" % "0.1.3"
[com.github.mlaccetti/etcd-client "0.1.3"]

Dependencies

compile (4)

Group / Artifact Type Version
org.apache.httpcomponents : httpasyncclient jar 4.1.1
com.google.guava : guava jar 19.0
com.google.code.gson : gson jar 2.6.2
org.slf4j : slf4j-api jar 1.7.19

test (3)

Group / Artifact Type Version
junit : junit jar 4.12
org.mockito : mockito-all jar 1.10.19
org.slf4j : slf4j-simple jar 1.7.19

Project Modules

There are no modules declared in this project.

jetcd: Java binding for etcd

TravisCI: Build Status

CircleCI: CircleCI Status

A simple Java client library for the awesome etcd

Uses the Apache HttpAsyncClient to implement watches without blocking a thread, and Google's Guava to give us the nice ListenableFuture interface.

Check out SmokeTest.java to see how this is used (and tested), but here's a quick code example:

EtcdClient client = new EtcdClient(URI.create("http://127.0.0.1:4001/"));

String key = "/watch";

EtcdResult result = this.client.set(key, "hello");
Assert.assertEquals("hello", result.value);

result = this.client.get(key);
Assert.assertEquals("hello", result.value);

ListenableFuture<EtcdResult> watchFuture = this.client.watch(key, result.index + 1);
Assert.assertFalse(watchFuture.isDone());

result = this.client.set(key, "world");
Assert.assertEquals("world", result.value);

EtcdResult watchResult = watchFuture.get(100, TimeUnit.MILLISECONDS);
Assert.assertNotNull(result);
Assert.assertEquals("world", result.value);

For a bit of background, check out the blog post.

Testing

  1. Export the IP for the node to use (this example is the typical IP of a docker-machine host:

    export HOST_IP="192.168.99.100"
    
  2. Fire up an etcd Docker container:

docker run -d -p 4001:4001 -p 2380:2380 -p 2379:2379 --name etcd quay.io/coreos/etcd:v2.0.3
-name etcd0
-advertise-client-urls http://${HOST_IP}:2379,http://${HOST_IP}:4001
-listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001
-initial-advertise-peer-urls http://${HOST_IP}:2380
-listen-peer-urls http://0.0.0.0:2380
-initial-cluster-token etcd-cluster-1
-initial-cluster etcd0=http://${HOST_IP}:2380
-initial-cluster-state new ```

Versions

Version
0.1.3
0.1.2
0.1.1