Search in sources :

Example 1 with GetInstancesResponse

use of io.servicecomb.serviceregistry.api.response.GetInstancesResponse in project java-chassis by ServiceComb.

the class ServiceRegistryClientImpl method getMicroserviceInstance.

@Override
public List<MicroserviceInstance> getMicroserviceInstance(String consumerId, String providerId) {
    Holder<GetInstancesResponse> holder = new Holder<>();
    IpPort ipPort = IpPortManager.INSTANCE.get();
    StringBuilder url = new StringBuilder(Const.MS_API_PATH);
    url.append(Const.MICROSERVICE_PATH).append("/").append(providerId).append(Const.INSTANCES_PATH);
    CountDownLatch countDownLatch = new CountDownLatch(1);
    RestUtils.get(ipPort, url.toString(), new RequestParam().addHeader("X-ConsumerId", consumerId), syncHandler(countDownLatch, GetInstancesResponse.class, holder));
    try {
        countDownLatch.await();
        if (holder.value != null) {
            return holder.value.getInstances();
        }
    } catch (Exception e) {
        LOGGER.error("query microservice instances {} failed", providerId, e);
    }
    return null;
}
Also used : Holder(javax.xml.ws.Holder) IpPort(io.servicecomb.foundation.common.net.IpPort) CountDownLatch(java.util.concurrent.CountDownLatch) GetInstancesResponse(io.servicecomb.serviceregistry.api.response.GetInstancesResponse) ClientException(io.servicecomb.serviceregistry.client.ClientException)

Aggregations

IpPort (io.servicecomb.foundation.common.net.IpPort)1 GetInstancesResponse (io.servicecomb.serviceregistry.api.response.GetInstancesResponse)1 ClientException (io.servicecomb.serviceregistry.client.ClientException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Holder (javax.xml.ws.Holder)1