use of com.ecwid.consul.v1.catalog.CatalogServicesRequest in project spring-cloud-consul by spring-cloud.
the class ConsulReactiveDiscoveryClient method getServices.
@Override
public Flux<String> getServices() {
return Flux.defer(() -> {
CatalogServicesRequest request = CatalogServicesRequest.newBuilder().setToken(properties.getAclToken()).setQueryParams(QueryParams.DEFAULT).build();
Response<Map<String, List<String>>> services = client.getCatalogServices(request);
return services == null ? Flux.empty() : Flux.fromIterable(services.getValue().keySet());
}).onErrorResume(exception -> {
logger.error("Error getting services from Consul.", exception);
return Flux.empty();
}).subscribeOn(Schedulers.boundedElastic());
}
use of com.ecwid.consul.v1.catalog.CatalogServicesRequest in project spring-cloud-consul by spring-cloud.
the class ConsulCatalogWatch method catalogServicesWatch.
@Timed("consul.watch-catalog-services")
public void catalogServicesWatch() {
try {
long index = -1;
if (this.catalogServicesIndex.get() != null) {
index = this.catalogServicesIndex.get().longValue();
}
CatalogServicesRequest request = CatalogServicesRequest.newBuilder().setQueryParams(new QueryParams(this.properties.getCatalogServicesWatchTimeout(), index)).setToken(this.properties.getAclToken()).build();
Response<Map<String, List<String>>> response = this.consul.getCatalogServices(request);
Long consulIndex = response.getConsulIndex();
if (consulIndex != null) {
this.catalogServicesIndex.set(BigInteger.valueOf(consulIndex));
}
if (log.isTraceEnabled()) {
log.trace("Received services update from consul: " + response.getValue() + ", index: " + consulIndex);
}
this.publisher.publishEvent(new HeartbeatEvent(this, consulIndex));
} catch (Exception e) {
log.error("Error watching Consul CatalogServices", e);
}
}
use of com.ecwid.consul.v1.catalog.CatalogServicesRequest in project polaris-java by polarismesh.
the class ConsulAPIConnector method syncGetServices.
@Override
public Services syncGetServices(ServiceUpdateTask serviceUpdateTask) {
Services services = new ServicesByProto(new ArrayList<>());
try {
CatalogServicesRequest request = CatalogServicesRequest.newBuilder().setQueryParams(QueryParams.DEFAULT).build();
ArrayList<String> serviceList = new ArrayList<>(this.consulClient.getCatalogServices(request).getValue().keySet());
for (String s : serviceList) {
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setService(s);
services.getServices().add(serviceInfo);
}
} catch (ConsulException e) {
throw ServerErrorResponseException.build(ErrorCode.SERVER_USER_ERROR.ordinal(), String.format("Get services of %s instances sync failed.", serviceUpdateTask.getServiceEventKey().getServiceKey()));
}
return services;
}
Aggregations