question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can catch put and delete events with Watch?

See original GitHub issue

I made a watch with jetcd 0.5.0, and process event with LoggingWatchListener. but It only call when any event complete, how can do like etcdctl: image

Here is my code:

public void keepWatch(String key){
        if (watchMap.containsKey(key)==false) {
            Watch watch = etcdClient.getWatchClient();
            ByteSequence keyBS = ByteSequence.from(key, StandardCharsets.UTF_8);
            Watch.Watcher watcher=watch.watch(
                    keyBS,
                    WatchOption.DEFAULT,
                    new LoggingWatchListener());
            log.debug("watch on key[{}]",key);
        }
        else{
            log.debug("we had watched on key[{}]",key);
        }
    }
class LoggingWatchListener implements Watch.Listener {
        @Override
        public void onNext(WatchResponse response) {
            log.info("watch[listener] - nextEvent");
            for(WatchEvent event:response.getEvents()){
                log.debug("watch[listener] - nextEvent - type:{}, KV:{}, PreKV:{}",
                        event.getEventType(),event.getKeyValue(),event.getPrevKV()
                );
            }

        }

        @Override
        public void onError(Throwable throwable) {
            log.error("watch[listener] - errorEvent - something wrong: {}",throwable.getMessage(),throwable);
        }

        @Override
        public void onCompleted() {
            log.debug("watch[listener] - completedEvent");
        }
    }

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14

github_iconTop GitHub Comments

3reactions
cleverpigcommented, Nov 24, 2020

I translated groove to java class, this doesn’t work for me.

public void testKeepWatch2() throws InterruptedException {
        Client client = Client.builder().endpoints("http://localhost:2379").build();
        Watch watch = client.getWatchClient();
        KV kv = client.getKVClient();
        ByteSequence key = ByteSequence.from(UUID.randomUUID().toString(), StandardCharsets.UTF_8);

        watch.watch(
                key,
                WatchOption.newBuilder().withProgressNotify(true).withPrevKV(true).build(),
                new Watch.Listener() {
                    @Override
                    public void onNext(WatchResponse response) {
                        log.info("onNext");
                    }

                    @Override
                    public void onError(Throwable throwable) {
                        log.error("onError - something wrong: {}", throwable.getMessage(), throwable);
                    }

                    @Override
                    public void onCompleted() {
                        log.debug("onCompleted");
                    }
                }
        );

        for(int i=0;i<99;i++){
            kv.put(key, ByteSequence.from(UUID.randomUUID().toString(), StandardCharsets.UTF_8));
            log.debug("put [{}]times",i+1);
            Thread.sleep(1000);
        }
    }

logging output without any listener’s event:

2020-11-24 11:22:50,669 DEBUG [com.bjinfotech.practice.etcd.EtcdUtilTest]:116 - <put [1]times>
2020-11-24 11:22:51,674 DEBUG [com.bjinfotech.practice.etcd.EtcdUtilTest]:116 - <put [2]times>
2020-11-24 11:22:52,674 DEBUG [com.bjinfotech.practice.etcd.EtcdUtilTest]:116 - <put [3]times>
2020-11-24 11:22:53,674 DEBUG [com.bjinfotech.practice.etcd.EtcdUtilTest]:116 - <put [4]times>
2020-11-24 11:22:54,674 DEBUG [com.bjinfotech.practice.etcd.EtcdUtilTest]:116 - <put [5]times>
2020-11-24 11:22:55,674 DEBUG [com.bjinfotech.practice.etcd.EtcdUtilTest]:116 - <put [6]times>
2020-11-24 11:22:56,674 DEBUG [com.bjinfotech.practice.etcd.EtcdUtilTest]:116 - <put [7]times>
2020-11-24 11:22:57,674 DEBUG [com.bjinfotech.practice.etcd.EtcdUtilTest]:116 - <put [8]times>
2020-11-24 11:22:58,674 DEBUG [com.bjinfotech.practice.etcd.EtcdUtilTest]:116 - <put [9]times>
....

etcd server output:

2020-11-24 11:22:51.602118 D | etcdserver/api/v3rpc: start time = 2020-11-24 11:22:51.6021187 +0800 CST m=+1093.828563401, time spent = 0s, remote = 127.0.0.1:54043, response type = /etcdserverpb.KV/Put, request count = 1, request size = 76, response count = 0, response size = 28, request content = key:"c291e080-825b-4990-a2f1-f1666d1d7cd8" value_size:36
2020-11-24 11:22:51.722125 D | etcdserver/api/v3rpc: start time = 2020-11-24 11:22:51.677123 +0800 CST m=+1093.903567701, time spent = 45.0026ms, remote = 127.0.0.1:54043, response type = /etcdserverpb.KV/Put, request count = 1, request size = 76, response count = 0, response size = 28, request content = key:"c291e080-825b-4990-a2f1-f1666d1d7cd8" value_size:36
2020-11-24 11:22:52.678180 D | etcdserver/api/v3rpc: start time = 2020-11-24 11:22:52.6781803 +0800 CST m=+1094.904625001, time spent = 0s, remote = 127.0.0.1:54043, response type = /etcdserverpb.KV/Put, request count = 1, request size = 76, response count = 0, response size = 28, request content = key:"c291e080-825b-4990-a2f1-f1666d1d7cd8" value_size:36
2020-11-24 11:22:53.677237 D | etcdserver/api/v3rpc: start time = 2020-11-24 11:22:53.6762373 +0800 CST m=+1095.902682001, time spent = 1.0001ms, remote = 127.0.0.1:54043, response type = /etcdserverpb.KV/Put, request count = 1, request size = 76, response count = 0, response size = 28, request content = key:"c291e080-825b-4990-a2f1-f1666d1d7cd8" value_size:36
2020-11-24 11:22:54.678294 D | etcdserver/api/v3rpc: start time = 2020-11-24 11:22:54.6782947 +0800 CST m=+1096.904739401, time spent = 0s, remote = 127.0.0.1:54043, response type = /etcdserverpb.KV/Put, request count = 1, request size = 76, response count = 0, response size = 28, request content = key:"c291e080-825b-4990-a2f1-f1666d1d7cd8" value_size:36
2020-11-24 11:22:55.677351 D | etcdserver/api/v3rpc: start time = 2020-11-24 11:22:55.6773518 +0800 CST m=+1097.903796501, time spent = 0s, remote = 127.0.0.1:54043, response type = /etcdserverpb.KV/Put, request count = 1, request size = 76, response count = 0, response size = 28, request content = key:"c291e080-825b-4990-a2f1-f1666d1d7cd8" value_size:36
2020-11-24 11:22:56.678409 D | etcdserver/api/v3rpc: start time = 2020-11-24 11:22:56.6784091 +0800 CST m=+1098.904853801, time spent = 0s, remote = 127.0.0.1:54043, response type = /etcdserverpb.KV/Put, request count = 1, request size = 76, response count = 0, response size = 28, request content = key:"c291e080-825b-4990-a2f1-f1666d1d7cd8" value_size:36

Btw, which etcdServer version are your? I tried 3.3.25 and 3.4.13.

0reactions
SadykovRcommented, Jun 10, 2022

I have the same issue. I tried to put and get values and it works well, but Watch doesnt works - Watch.Listener doesn’t fires when I put a value. I use 0.5.0 version. P.S. Also tried to add Watch and test it using etcdctl tool on the same server - works fine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Check and update your calendar on Apple Watch
Delete an event you created: Tap an event, tap Delete, then tap Delete again. If this is a recurring event, you can delete...
Read more >
How To Delete Calendar Events On iPhone - YouTube
0:00 Intro0:07 Deleting calendar events0:38 Deleting recurring event0:43 Deleting singular eventIn this video, we will show you how to ...
Read more >
Delete Multiple Events at Once on Google Calendar - YouTube
How to bulk delete multiple events at once on Google Calendar. Deleting recurring events is easy and bulk deleting single events is possible ......
Read more >
Unable to delete a calendar event on Galaxy phone or tablet
Open the Calendar app, and tap the repeating event. Tap Delete, and then tap All events in series. Related ...
Read more >
Kubernetes API Concepts
Clients can send a list or a get and then make a follow-up watch request. ... the Kubernetes API provides a watch event...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found