use of com.baidu.brpc.protocol.stargate.StargateURI in project brpc-java by baidu.
the class StargateZookeeperNamingService method lookup.
@Override
public List<ServiceInstance> lookup(SubscribeInfo subscribeInfo) {
String path = buildParentNodePath(resolveGroup(subscribeInfo), subscribeInfo.getInterfaceName(), resolveVersion(subscribeInfo));
List<ServiceInstance> instances = new ArrayList<ServiceInstance>();
try {
List<String> childList = client.getChildren().forPath(path);
for (String child : childList) {
// 跨过所有客户端节点
if (StargateConstants.ZK_CONSUMER_DIR.equals(child)) {
continue;
}
String childPath = path + "/" + child;
try {
String childData = new String(client.getData().forPath(childPath));
StargateURI uri = new StargateURI.Builder(childData).build();
ServiceInstance instance = new ServiceInstance(uri.getHost(), uri.getPort());
if (subscribeInfo != null && StringUtils.isNoneBlank(subscribeInfo.getServiceId())) {
instance.setServiceName(subscribeInfo.getServiceId());
}
instances.add(instance);
} catch (Exception getDataFailedException) {
log.warn("get child data failed, path:{}, ex:", childPath, getDataFailedException);
}
}
log.info("lookup {} instances from {}", instances.size(), url);
} catch (Exception ex) {
log.warn("lookup service instance list failed from {}, msg={}", url, ex.getMessage());
if (!subscribeInfo.isIgnoreFailOfNamingService()) {
throw new RpcException("lookup end point list failed from zookeeper failed", ex);
}
}
return instances;
}
Aggregations