Search in sources :

Example 1 with HealthServicesRequest

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);
}
Also used : HealthServicesRequest(com.ecwid.consul.v1.health.HealthServicesRequest)

Example 2 with HealthServicesRequest

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);
    }
}
Also used : HealthServicesRequest(com.ecwid.consul.v1.health.HealthServicesRequest) QueryParams(com.ecwid.consul.v1.QueryParams) ArrayList(java.util.ArrayList) List(java.util.List) ProviderGroup(com.alipay.sofa.rpc.client.ProviderGroup)

Example 3 with HealthServicesRequest

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);
}
Also used : HealthServicesRequest(com.ecwid.consul.v1.health.HealthServicesRequest) QueryParams(com.ecwid.consul.v1.QueryParams)

Example 4 with HealthServicesRequest

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));
    }
}
Also used : HealthServicesRequest(com.ecwid.consul.v1.health.HealthServicesRequest) HealthService(com.ecwid.consul.v1.health.model.HealthService) List(java.util.List) ArrayList(java.util.ArrayList)

Example 5 with HealthServicesRequest

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();
}
Also used : HealthServicesRequest(com.ecwid.consul.v1.health.HealthServicesRequest) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

HealthServicesRequest (com.ecwid.consul.v1.health.HealthServicesRequest)10 List (java.util.List)8 ConsulClient (com.ecwid.consul.v1.ConsulClient)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 QueryParams (com.ecwid.consul.v1.QueryParams)3 HealthService (com.ecwid.consul.v1.health.model.HealthService)2 ProviderGroup (com.alipay.sofa.rpc.client.ProviderGroup)1 ConsulException (com.ecwid.consul.ConsulException)1 DefaultInstance (com.tencent.polaris.api.pojo.DefaultInstance)1