in clients/service-center-client/src/main/java/org/apache/servicecomb/service/center/client/ServiceCenterDiscovery.java [156:197]
private List<SubscriptionKey> pullInstance(SubscriptionKey k, SubscriptionValue v, boolean sendChangedEvent) {
if (myselfServiceId == null) {
// registration not ready
return Collections.emptyList();
}
List<SubscriptionKey> failedKeys = new ArrayList<>();
try {
FindMicroserviceInstancesResponse instancesResponse = serviceCenterClient
.findMicroserviceInstance(myselfServiceId, k.appId, k.serviceName, ALL_VERSION, v.revision);
if (instancesResponse.isModified()) {
List<MicroserviceInstance> instances = instancesResponse.getMicroserviceInstancesResponse().getInstances()
== null ? Collections.emptyList() : instancesResponse.getMicroserviceInstancesResponse().getInstances();
setMicroserviceInfo(instances);
LOGGER.info("Instance changed event. "
+ "Current: revision={}, instances={}. "
+ "Origin: revision={}, instances={}. "
+ "appId={}, serviceName={}.",
instancesResponse.getRevision(),
instanceToString(instances),
v.revision,
instanceToString(v.instancesCache),
k.appId,
k.serviceName
);
v.instancesCache = instances;
v.revision = instancesResponse.getRevision();
if (sendChangedEvent) {
eventBus.post(new InstanceChangedEvent(k.appId, k.serviceName,
v.instancesCache));
}
}
} catch (Exception e) {
LOGGER.warn("find service {}#{} instance failed.", k.appId, k.serviceName, e);
if (!(e.getCause() instanceof IOException)) {
// for IOException, do not remove cache, or when service center
// not available, invocation between microservices will fail.
failedKeys.add(k);
}
}
return failedKeys;
}