Search in sources :

Example 1 with QueryParams

use of com.recurly.v3.QueryParams in project dawdler-series by srchen1987.

the class ConsulConfigClient method start.

@Override
public void start() {
    if (watchKeys != null) {
        for (String watchKey : watchKeys) {
            long updateIndex = flushCache(watchKey);
            executor.execute(() -> {
                try {
                    long index = updateIndex;
                    while (start) {
                        Response<List<String>> responseKeys = client.getKVKeysOnly(watchKey, separator, token, new QueryParams(waitTime, index));
                        if (responseKeys == null) {
                            Thread.sleep(10000);
                            logger.error("not found watchKey {} !", watchKey);
                            continue;
                        }
                        long currentIndex = responseKeys.getConsulIndex();
                        if (currentIndex != index) {
                            index = currentIndex;
                            flushCache(watchKey);
                        }
                    }
                } catch (Throwable e) {
                    logger.error("", e);
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException interruptedException) {
                    // ignore
                    }
                }
            });
        }
    }
}
Also used : List(java.util.List) QueryParams(com.ecwid.consul.v1.QueryParams)

Example 2 with QueryParams

use of com.recurly.v3.QueryParams 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 QueryParams

use of com.recurly.v3.QueryParams 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 QueryParams

use of com.recurly.v3.QueryParams in project motan by weibocom.

the class ConsulRegistryService method getNodes.

@Override
public List<JSONObject> getNodes(String dcGroup, String service, String nodeType) {
    List<JSONObject> results = new ArrayList<JSONObject>();
    List<Check> checks = consulClient.getHealthChecksForService(getGroupName(dcGroup), new QueryParams(getDcName(dcGroup))).getValue();
    for (Check check : checks) {
        String serviceId = check.getServiceId();
        String[] strings = serviceId.split("-");
        if (strings[1].equals(service)) {
            Check.CheckStatus status = check.getStatus();
            JSONObject node = new JSONObject();
            if (nodeType.equals(status.toString())) {
                node.put("host", strings[0]);
                node.put("info", null);
                results.add(node);
            }
        }
    }
    return results;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) Check(com.ecwid.consul.v1.health.model.Check) QueryParams(com.ecwid.consul.v1.QueryParams)

Example 5 with QueryParams

use of com.recurly.v3.QueryParams in project spring-cloud-consul by spring-cloud.

the class EventService method watch.

public List<Event> watch(Long lastIndex) {
    // TODO: parameterized or configurable watch time
    long index = -1;
    if (lastIndex != null) {
        index = lastIndex;
    }
    int eventTimeout = 5;
    if (this.properties != null) {
        eventTimeout = this.properties.getEventTimeout();
    }
    Response<List<Event>> watch = this.consul.eventList(EventListRequest.newBuilder().setQueryParams(new QueryParams(eventTimeout, index)).build());
    return filterEvents(readEvents(watch), lastIndex);
}
Also used : List(java.util.List) QueryParams(com.ecwid.consul.v1.QueryParams)

Aggregations

QueryParams (com.ecwid.consul.v1.QueryParams)13 List (java.util.List)9 HealthServicesRequest (com.ecwid.consul.v1.health.HealthServicesRequest)3 ArrayList (java.util.ArrayList)3 HealthService (com.ecwid.consul.v1.health.model.HealthService)2 Timed (io.micrometer.core.annotation.Timed)2 JSONObject (com.alibaba.fastjson.JSONObject)1 ProviderGroup (com.alipay.sofa.rpc.client.ProviderGroup)1 ConsulException (com.ecwid.consul.ConsulException)1 CatalogServicesRequest (com.ecwid.consul.v1.catalog.CatalogServicesRequest)1 Check (com.ecwid.consul.v1.health.model.Check)1 GetValue (com.ecwid.consul.v1.kv.model.GetValue)1 Pager (com.recurly.v3.Pager)1 QueryParams (com.recurly.v3.QueryParams)1 DefaultInstance (com.tencent.polaris.api.pojo.DefaultInstance)1 ConsulService (com.weibo.api.motan.registry.consul.ConsulService)1 Type (java.lang.reflect.Type)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 MediaType (okhttp3.MediaType)1