use of com.orbitz.consul.cache.ServiceHealthCache in project wildfly-swarm by wildfly-swarm.
the class CatalogWatcher method setupWatcher.
private void setupWatcher(String serviceName) {
if (watchers.containsKey(serviceName)) {
return;
}
CatalogOptions options = ImmutableCatalogOptions.builder().build();
ServiceHealthCache healthCache = ServiceHealthCache.newCache(this.healthClientInjector.getValue(), serviceName, true, options, 5);
try {
healthCache.addListener(new ServiceCacheListener(serviceName, this.topologyManagerInjector.getValue()));
healthCache.start();
healthCache.awaitInitialized(1, TimeUnit.SECONDS);
this.watchers.put(serviceName, healthCache);
} catch (Exception e) {
ConsulTopologyMessages.MESSAGES.errorSettingUpCatalogWatcher(serviceName, e);
}
}
use of com.orbitz.consul.cache.ServiceHealthCache in project jim-framework by jiangmin168168.
the class ConsulDiscoveryService method getUrls.
@Override
public List<RpcURL> getUrls(String registryHost, int registryPort) {
List<RpcURL> urls = Lists.newArrayList();
Consul consul = this.buildConsul(registryHost, registryPort);
HealthClient client = consul.healthClient();
String name = CONSUL_NAME;
ConsulResponse object = client.getAllServiceInstances(name);
List<ImmutableServiceHealth> serviceHealths = (List<ImmutableServiceHealth>) object.getResponse();
for (ImmutableServiceHealth serviceHealth : serviceHealths) {
RpcURL url = new RpcURL();
url.setHost(serviceHealth.getService().getAddress());
url.setPort(serviceHealth.getService().getPort());
urls.add(url);
}
try {
ServiceHealthCache serviceHealthCache = ServiceHealthCache.newCache(client, name);
serviceHealthCache.addListener(new ConsulCache.Listener<ServiceHealthKey, ServiceHealth>() {
@Override
public void notify(Map<ServiceHealthKey, ServiceHealth> map) {
logger.info("serviceHealthCache.addListener notify");
RpcClientInvokerCache.clear();
}
});
serviceHealthCache.start();
} catch (Exception e) {
logger.info("serviceHealthCache.start error:", e);
}
return urls;
}
Aggregations