in clients/service-center-client/src/main/java/org/apache/servicecomb/service/center/client/ServiceCenterRegistration.java [127:187]
public void execute() {
try {
RegisteredMicroserviceResponse serviceResponse = serviceCenterClient.queryServiceId(microservice);
if (serviceResponse == null) {
RegisteredMicroserviceResponse response = serviceCenterClient.registerMicroservice(microservice);
if (StringUtils.isEmpty(response.getServiceId())) {
LOGGER.error("register microservice failed, and will try again.");
eventBus.post(new MicroserviceRegistrationEvent(false, microservice));
startTask(new BackOffSleepTask(failedCount + 1, new RegisterMicroserviceTask(failedCount + 1)));
return;
}
microservice.setServiceId(response.getServiceId());
microserviceInstance.setServiceId(response.getServiceId());
microserviceInstance.setMicroservice(microservice);
eventBus.post(new MicroserviceRegistrationEvent(true, microservice));
startTask(new RegisterSchemaTask(0));
} else {
Microservice newMicroservice = serviceCenterClient.getMicroserviceByServiceId(serviceResponse.getServiceId());
Map<String, String> propertiesTemp = microservice.getProperties();
microservice.setProperties(newMicroservice.getProperties());
microservice.getProperties().putAll(propertiesTemp);
if (serviceCenterClient.updateMicroserviceProperties(serviceResponse.getServiceId(),
microservice.getProperties())) {
LOGGER.info(
"microservice is already registered. Update microservice properties successfully. properties=[{}]",
microservice.getProperties());
} else {
LOGGER.error("microservice is already registered. Update microservice properties failed. properties=[{}]",
microservice.getProperties());
}
microservice.setServiceId(serviceResponse.getServiceId());
microserviceInstance.setServiceId(serviceResponse.getServiceId());
microserviceInstance.setMicroservice(microservice);
if (isSwaggerDifferent(newMicroservice)) {
if (serviceCenterConfiguration.isCanOverwriteSwagger()) {
LOGGER.warn("Service has already registered, but schema ids not equal, try to register it again");
eventBus.post(new MicroserviceRegistrationEvent(true, microservice));
startTask(new RegisterSchemaTask(0));
return;
}
if (serviceCenterConfiguration.isIgnoreSwaggerDifferent()) {
LOGGER.warn("Service has already registered, but schema ids not equal. Ignore and continue to register");
} else {
throw new IllegalStateException(
"Service has already registered, but schema ids not equal, stop register. "
+ "Change the microservice version or delete the old microservice info and try again.");
}
}
eventBus.post(new MicroserviceRegistrationEvent(true, microservice));
startTask(new RegisterMicroserviceInstanceTask(0));
}
} catch (IllegalStateException e) {
throw e;
} catch (Exception e) {
LOGGER.error("register microservice failed, and will try again.", e);
eventBus.post(new MicroserviceRegistrationEvent(false, microservice));
startTask(new BackOffSleepTask(failedCount + 1, new RegisterMicroserviceTask(failedCount + 1)));
}
}