|
|
@ -151,7 +151,8 @@ public class EtcdRegistry implements Registry { |
|
|
|
public boolean subscribe(String path, SubscribeListener listener) { |
|
|
|
public boolean subscribe(String path, SubscribeListener listener) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
ByteSequence watchKey = byteSequence(path); |
|
|
|
ByteSequence watchKey = byteSequence(path); |
|
|
|
WatchOption watchOption = WatchOption.newBuilder().isPrefix(true).build(); |
|
|
|
WatchOption watchOption = |
|
|
|
|
|
|
|
WatchOption.newBuilder().withPrevKV(true).isPrefix(true).build(); |
|
|
|
watcherMap.computeIfAbsent(path, |
|
|
|
watcherMap.computeIfAbsent(path, |
|
|
|
$ -> client.getWatchClient().watch(watchKey, watchOption, watchResponse -> { |
|
|
|
$ -> client.getWatchClient().watch(watchKey, watchOption, watchResponse -> { |
|
|
|
for (WatchEvent event : watchResponse.getEvents()) { |
|
|
|
for (WatchEvent event : watchResponse.getEvents()) { |
|
|
@ -352,7 +353,11 @@ public class EtcdRegistry implements Registry { |
|
|
|
|
|
|
|
|
|
|
|
switch (event.getEventType()) { |
|
|
|
switch (event.getEventType()) { |
|
|
|
case PUT: |
|
|
|
case PUT: |
|
|
|
type(Type.ADD); |
|
|
|
if (event.getPrevKV().getKey().isEmpty()) { |
|
|
|
|
|
|
|
type(Type.ADD); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
type(Type.UPDATE); |
|
|
|
|
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case DELETE: |
|
|
|
case DELETE: |
|
|
|
type(Type.REMOVE); |
|
|
|
type(Type.REMOVE); |
|
|
|