Jetcdetcd 的 Java 客戶端
Jetcd 是 etcd 的簡(jiǎn)單 Java 客戶端開發(fā)包。etcd 是 CoreOS 中的高可用 Key/Value 存儲(chǔ)和
示例代碼:
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);評(píng)論
圖片
表情
