org.zodiac.eureka.client.EurekaAppDiscoveryClient Maven / Gradle / Ivy
package org.zodiac.eureka.client;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.zodiac.core.application.AppInstance;
import org.zodiac.core.application.ApplicationInfo;
import org.zodiac.core.bootstrap.discovery.AppDiscoveryClient;
import org.zodiac.eureka.base.instance.EurekaAppInstance;
import com.netflix.appinfo.EurekaInstanceConfig;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient;
import com.netflix.discovery.EurekaClientConfig;
import com.netflix.discovery.shared.Application;
import com.netflix.discovery.shared.Applications;
public class EurekaAppDiscoveryClient implements AppDiscoveryClient {
public static final String DESCRIPTION = "Eureka Application Discovery Client";
private ApplicationInfo applicationInfo;
private final EurekaClientConfig clientConfig;
private final EurekaInstanceConfig instanceConfig;
private final EurekaClient eurekaClient;
public EurekaAppDiscoveryClient(ApplicationInfo applicationInfo, EurekaClientConfig clientConfig,
EurekaInstanceConfig instanceConfig, EurekaClient eurekaClient) {
this.applicationInfo = applicationInfo;
this.clientConfig = clientConfig;
this.instanceConfig = instanceConfig;
this.eurekaClient = eurekaClient;
}
@Override
public String clientDescription() {
return DESCRIPTION;
}
@Override
public List getAppInstances(String serviceId) {
List infos = this.eurekaClient.getInstancesByVipAddress(serviceId, false);
List instances = new ArrayList<>();
for (InstanceInfo instance : infos) {
instances.add(new EurekaAppInstance(applicationInfo, instance, clientConfig, instanceConfig));
}
return instances;
}
@Override
public List getServiceList() {
Applications applications = this.eurekaClient.getApplications();
if (applications == null) {
return Collections.emptyList();
}
List registered = applications.getRegisteredApplications();
List names = new ArrayList<>();
for (Application app : registered) {
if (app.getInstances().isEmpty()) {
continue;
}
names.add(app.getName().toLowerCase());
}
return names;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy