use of org.apache.servicecomb.serviceregistry.api.response.RegisterInstanceResponse in project incubator-servicecomb-java-chassis by apache.
the class ServiceRegistryClientImpl method registerMicroserviceInstance.
@Override
public String registerMicroserviceInstance(MicroserviceInstance instance) {
Holder<RegisterInstanceResponse> holder = new Holder<>();
IpPort ipPort = ipPortManager.getAvailableAddress();
try {
RegisterInstanceRequest request = new RegisterInstanceRequest();
request.setInstance(instance);
byte[] body = JsonUtils.writeValueAsBytes(request);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("register microservice: {}", new String(body, Charset.defaultCharset()));
}
CountDownLatch countDownLatch = new CountDownLatch(1);
RestUtils.post(ipPort, String.format(Const.REGISTRY_API.MICROSERVICE_INSTANCE_OPERATION_ALL, instance.getServiceId()), new RequestParam().setBody(body), syncHandler(countDownLatch, RegisterInstanceResponse.class, holder));
countDownLatch.await();
if (holder.value != null) {
return holder.value.getInstanceId();
}
} catch (Exception e) {
LOGGER.error("register microservice instance {} failed", instance.getServiceId(), e);
}
return null;
}
Aggregations