use of io.servicecomb.serviceregistry.api.response.FindInstancesResponse in project java-chassis by ServiceComb.
the class ServiceRegistryClientImpl method findServiceInstance.
@Override
public List<MicroserviceInstance> findServiceInstance(String selfMicroserviceId, String appId, String serviceName, String versionRule) {
Holder<FindInstancesResponse> holder = new Holder<>();
IpPort ipPort = IpPortManager.INSTANCE.get();
StringBuilder url = new StringBuilder(Const.MS_API_PATH);
url.append(Const.INSTANCES_PATH);
CountDownLatch countDownLatch = new CountDownLatch(1);
RestUtils.get(ipPort, url.toString(), new RequestParam().addQueryParam("appId", appId).addQueryParam("serviceName", serviceName).addQueryParam("version", versionRule).addHeader("X-ConsumerId", selfMicroserviceId), syncHandler(countDownLatch, FindInstancesResponse.class, holder));
try {
countDownLatch.await();
if (holder.value == null) {
// error
return null;
}
List<MicroserviceInstance> list = holder.value.getInstances();
if (list == null) {
return new ArrayList<>();
}
return list;
} catch (Exception e) {
LOGGER.error("find microservice instance {}/{}/{} failed", appId, serviceName, versionRule, e);
}
return null;
}
Aggregations