Hi
I use the following code to do test the jetcd watch API, my question is: how to cancel the watch with the watch API?
String path="/hello"
String endpoint = "http://127.0.0.1:2379";
CountDownLatch latch = new CountDownLatch(1);
ByteSequence key = ByteSequence.from(path, UTF_8);
Watch.Listener listener = Watch.listener(response -> {
for (WatchEvent event : response.getEvents()) {
Assertions.assertEquals("PUT", event.getEventType().toString());
Assertions.assertEquals(path, event.getKeyValue().getKey().toString(UTF_8));
Assertions.assertEquals("Hello", event.getKeyValue().getValue().toString(UTF_8));
}
latch.countDown();
});
try (Client client = Client.builder().endpoints(endpoint).build();
Watch watch = client.getWatchClient();
Watch.Watcher watcher = watch.watch(key, listener)) {
// try to modify the key
client.getKVClient().put(ByteSequence.from(path, UTF_8), ByteSequence.from("Hello", UTF_8));
latch.await();
} catch (Exception e) {
Assertions.fail(e.getMessage());
}
According to the doc, a watch_id is required to cancel the watch.
Is there a way to obtain the watch id?
Hi
I use the following code to do test the jetcd watch API, my question is: how to cancel the watch with the watch API?
According to the doc, a watch_id is required to cancel the watch.
Is there a way to obtain the watch id?