Fix zookeeper instance update (#11212)

This commit is contained in:
Albumen Kevin 2022-12-29 17:12:33 +08:00 committed by GitHub
parent 1ecc00a713
commit e86e6e3209
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 0 deletions

View File

@ -42,6 +42,8 @@ import java.util.concurrent.CountDownLatch;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_ZOOKEEPER_EXCEPTION;
import static org.apache.dubbo.common.function.ThrowableFunction.execute;
import static org.apache.dubbo.metadata.RevisionResolver.EMPTY_REVISION;
import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getExportedServicesRevision;
import static org.apache.dubbo.registry.zookeeper.util.CuratorFrameworkUtils.build;
import static org.apache.dubbo.registry.zookeeper.util.CuratorFrameworkUtils.buildCuratorFramework;
import static org.apache.dubbo.registry.zookeeper.util.CuratorFrameworkUtils.buildServiceDiscovery;
@ -106,6 +108,19 @@ public class ZookeeperServiceDiscovery extends AbstractServiceDiscovery {
}
}
@Override
protected void doUpdate(ServiceInstance serviceInstance) throws RuntimeException {
if (!EMPTY_REVISION.equals(getExportedServicesRevision(serviceInstance))) {
reportMetadata(serviceInstance.getServiceMetadata());
}
try {
serviceDiscovery.updateService(build(serviceInstance));
} catch (Exception e) {
throw new RpcException(REGISTRY_EXCEPTION, "Failed register instance " + serviceInstance.toString(), e);
}
}
@Override
public Set<String> getServices() {
return doInServiceDiscovery(s -> new LinkedHashSet<>(s.queryForNames()));