jetcd

Jetcd is a java etcd v2 client

License

License

Categories

Categories

jetcd Data Databases
GroupId

GroupId

com.lindzh
ArtifactId

ArtifactId

jetcd
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

jetcd
Jetcd is a java etcd v2 client
Project URL

Project URL

http://maven.apache.org
Source Code Management

Source Code Management

https://github.com/lindzh/jetcd

Download jetcd

How to add to project

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

Dependencies

compile (6)

Group / Artifact Type Version
log4j : log4j jar 1.2.16
com.fasterxml.jackson.core : jackson-core jar 2.2.0
com.fasterxml.jackson.core : jackson-annotations jar 2.2.0
com.fasterxml.jackson.core : jackson-databind jar 2.2.0
org.apache.httpcomponents : httpclient jar 4.3.5
org.apache.httpcomponents : httpasyncclient jar 4.0.2

Project Modules

There are no modules declared in this project.

a simple etcd client for java

watch auto notify for change,easy to use


model


maven 引入依赖

<dependency>
  <groupId>com.lindzh</groupId>
  <artifactId>jetcd</artifactId>
  <version>1.0.1</version>
</dependency>

simple setting config operation

	String key = "/testKey";
	EtcdResult result = client.get(key);
	result = client.set(key, "11111111");
	result = client.set(key, null, 10);
	Thread.sleep(11000);
	result = client.get(key);
	result = client.set(key, "222222");
	result = client.get(key);
	result = client.del(key);
	result = client.get(key);

cas operation

String key = "/testCas";
client.cas(key, "testCas-1", false);
EtcdResult result = client.get(key);
client.cas(key, "testCas-2", false);
result = client.get(key);
client.cas(key, "testCas-2", true);
result = client.get(key);

use watch call back for change notify

String key = "/testCallback";
EtcdResult result = client.get(key);
result = client.set(key, "11111111", false);
result = client.get(key);
System.out.println("set:" +JSONUtils.toJSON(result));
client.watch(key, new EtcdWatchCallback() {
	public void onChange(EtcdChangeResult future) {
		EtcdResult etcdResult = future.getResult();
		if(etcdResult!=null){
			System.out.println("change:" +JSONUtils.toJSON(etcdResult));
		}
	}
});

dir operation

String dirKey = "/dirTestKey";
//delete dir
EtcdResult result = client.delDir(dirKey, true);
//create dir
result = client.dir(dirKey);
//add sub dir
result = client.dir(dirKey+"/subdir1");
result = client.dir(dirKey+"/subdir2");
result = client.children(dirKey, true, false);
result = client.delDir(dirKey+"/subdir2", true);
result = client.children(dirKey, true, false);
result = client.delDir(dirKey, true);
result = client.children(dirKey, true, false);

suquence ordered queue for lock

String queue = "/testQueue";
//queue name is a directory
client.delDir(queue, true);
EtcdResult result = client.queue(queue, "job1");
result = client.queue(queue, "job2");
EtcdResult job2 = result;
result = client.queue(queue, "job3");
String delJob3 = result.getNode().getKey();
result = client.children(queue, true, true);
result = client.queue(queue, "job-ttl",10);
result = client.children(queue, true, true);
Thread.currentThread().sleep(10000);
result = client.children(queue, true, true);
//set key ttl
EtcdResult etcdResult = client.set(job2.getNode().getKey(), job2.getNode().getValue(), 6);
Thread.currentThread().sleep(10000);
result = client.children(queue, true, true);
client.del(delJob3);
result = client.children(queue, true, true);

Versions

Version
1.0.1