Search in sources :

Example 1 with InstanceChangedEvent

use of org.apache.servicecomb.service.center.client.DiscoveryEvents.InstanceChangedEvent in project java-chassis by ServiceComb.

the class ServiceCenterDiscovery method pullInstance.

private void pullInstance(SubscriptionKey k, SubscriptionValue v) {
    if (myselfServiceId == null) {
        // registration not ready
        return;
    }
    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();
            eventBus.post(new InstanceChangedEvent(k.appId, k.serviceName, v.instancesCache));
        }
    } catch (Exception e) {
        LOGGER.error("find service {}#{} instance failed.", k.appId, k.serviceName, e);
        failedInstances.add(k);
    }
}
Also used : InstanceChangedEvent(org.apache.servicecomb.service.center.client.DiscoveryEvents.InstanceChangedEvent) MicroserviceInstance(org.apache.servicecomb.service.center.client.model.MicroserviceInstance) FindMicroserviceInstancesResponse(org.apache.servicecomb.service.center.client.model.FindMicroserviceInstancesResponse)

Aggregations

InstanceChangedEvent (org.apache.servicecomb.service.center.client.DiscoveryEvents.InstanceChangedEvent)1 FindMicroserviceInstancesResponse (org.apache.servicecomb.service.center.client.model.FindMicroserviceInstancesResponse)1 MicroserviceInstance (org.apache.servicecomb.service.center.client.model.MicroserviceInstance)1