use of com.ecwid.consul.v1.health.HealthServicesRequest in project sofa-rpc by sofastack.
the class HealthServiceInformer method init.
public void init() {
HealthServicesRequest request = HealthServicesRequest.newBuilder().setTag(tag).setQueryParams(QueryParams.DEFAULT).setToken(properties.getToken()).setPassing(true).build();
this.currentData = consulClient.getHealthServices(serviceName, request);
this.watchExecutor = Executors.newSingleThreadScheduledExecutor();
this.watchExecutor.scheduleWithFixedDelay(this::watchHealthService, properties.getLookupInterval(), properties.getLookupInterval(), TimeUnit.MILLISECONDS);
}
use of com.ecwid.consul.v1.health.HealthServicesRequest in project sofa-rpc by sofastack.
the class HealthServiceInformer method watchHealthService.
private void watchHealthService() {
try {
HealthServicesRequest request = HealthServicesRequest.newBuilder().setTag(tag).setQueryParams(new QueryParams(properties.getWatchTimeout(), currentData.getConsulIndex())).setToken(properties.getToken()).setPassing(true).build();
Response<List<HealthService>> response = consulClient.getHealthServices(serviceName, request);
if (response.getConsulIndex().equals(currentData.getConsulIndex())) {
return;
}
this.currentData = response;
ProviderGroup providerGroup = new ProviderGroup(currentProviders());
listeners.stream().filter(Objects::nonNull).forEach(l -> l.updateProviders(providerGroup));
} catch (Exception e) {
LOGGER.error(LogCodes.getLog(LogCodes.ERROR_WATCH_HEALTH, "Consul"), e);
}
}
use of com.ecwid.consul.v1.health.HealthServicesRequest in project brpc-java by baidu.
the class ConsulNamingService method lookupHealthService.
public Response<List<HealthService>> lookupHealthService(String serviceName, long lastConsulIndex) {
QueryParams queryParams = new QueryParams(ConsulConstants.CONSUL_BLOCK_TIME_SECONDS, lastConsulIndex);
HealthServicesRequest request = HealthServicesRequest.newBuilder().setTag(ConsulConstants.CONSUL_SERVICE_TAG).setQueryParams(queryParams).setPassing(true).build();
return client.getHealthServices(serviceName, request);
}
use of com.ecwid.consul.v1.health.HealthServicesRequest in project spring-cloud-consul by spring-cloud.
the class ConsulDiscoveryClient method addInstancesToList.
private void addInstancesToList(List<ServiceInstance> instances, String serviceId, QueryParams queryParams) {
HealthServicesRequest.Builder requestBuilder = HealthServicesRequest.newBuilder().setPassing(properties.isQueryPassing()).setQueryParams(queryParams).setToken(properties.getAclToken());
String[] queryTags = properties.getQueryTagsForService(serviceId);
if (queryTags != null) {
requestBuilder.setTags(queryTags);
}
HealthServicesRequest request = requestBuilder.build();
Response<List<HealthService>> services = this.client.getHealthServices(serviceId, request);
for (HealthService service : services.getValue()) {
instances.add(new ConsulServiceInstance(service, serviceId));
}
}
use of com.ecwid.consul.v1.health.HealthServicesRequest in project spring-cloud-consul by spring-cloud.
the class ConsulReactiveDiscoveryClient method getHealthServices.
private List<HealthService> getHealthServices(String serviceId) {
HealthServicesRequest.Builder requestBuilder = HealthServicesRequest.newBuilder().setPassing(properties.isQueryPassing()).setQueryParams(QueryParams.DEFAULT).setToken(properties.getAclToken());
String[] queryTags = properties.getQueryTagsForService(serviceId);
if (queryTags != null) {
requestBuilder.setTags(queryTags);
}
HealthServicesRequest request = requestBuilder.build();
Response<List<HealthService>> services = client.getHealthServices(serviceId, request);
return services == null ? Collections.emptyList() : services.getValue();
}
Aggregations