-
Notifications
You must be signed in to change notification settings - Fork 314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can catch put and delete events with Watch? #853
Comments
What do you mean exactly ? |
I mean How to monitor and process events with etcd watcher? |
can you please try to update to the latest release ? |
Yes, I'd checked out the master and compile & install it. |
how do you set up the watcher ? |
can you provide a reproducer ? a failing test would be very welcome |
Sure!
|
I've create the following example: @Grab(group = 'org.slf4j', module = 'slf4j-simple', version = '1.7.30')
@Grab(group = 'io.etcd', module = 'jetcd-core', version = '0.5.4')
import io.etcd.jetcd.ByteSequence
import io.etcd.jetcd.Client
import io.etcd.jetcd.Watch
import io.etcd.jetcd.options.WatchOption
import io.etcd.jetcd.watch.WatchResponse
import org.slf4j.LoggerFactory
import java.nio.charset.StandardCharsets
def log = LoggerFactory.getLogger('watcher')
def client = Client.builder().endpoints(args[0]).build()
def watch = client.getWatchClient()
def kv = client.getKVClient()
def key = ByteSequence.from(UUID.randomUUID().toString(), StandardCharsets.UTF_8)
watch.watch(
key,
WatchOption.newBuilder().withProgressNotify(true).withPrevKV(true).build(),
new Watch.Listener() {
@Override
void onNext(WatchResponse response) {
log.info("onNext")
response.events.each {
log.info("""
nextEvent:
type: ${it.getEventType()}
KV: ${it.keyValue.key.toString(StandardCharsets.UTF_8)} -> ${it.keyValue.value.toString(StandardCharsets.UTF_8)}
PreKV: ${it.prevKV.key.toString(StandardCharsets.UTF_8)} -> ${it.prevKV.value.toString(StandardCharsets.UTF_8)}
""".stripIndent())
}
}
@Override
void onError(Throwable throwable) {
log.error("onError - something wrong: {}", throwable.message, throwable);
}
@Override
void onCompleted() {
log.debug("onCompleted");
}
}
)
while (true) {
kv.put(key, ByteSequence.from(UUID.randomUUID().toString(), StandardCharsets.UTF_8))
Thread.sleep(1000)
} It requires groovy and if I run it with:
I get something like:
So to me it appears to work, am I missing something ? |
I translated groove to java class, this doesn't work for me.
logging output without any listener's event:
etcd server output:
Btw, which etcdServer version are your? I tried 3.3.25 and 3.4.13. |
I've tested with both 3.3 and 3.4, command line to run it is:
Then you can try my example with jbang using a gist:
And it does work for me, I suspect you have some issue in how you start etcd |
Jbang is ok. |
So you have something wrong on your set-up. Did you try to use the exact same dependencies I've used for jbang/groovy ? |
This issue is stale because it has been open 60 days with no activity. |
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 made a watch with jetcd 0.5.0, and process event with LoggingWatchListener.
![image](https://user-images.githubusercontent.com/580435/99215252-5626c780-280d-11eb-8373-6d2c00f0f824.png)
but It only call when any event complete, how can do like etcdctl:
Here is my code:
The text was updated successfully, but these errors were encountered: