use of mousio.etcd4j.requests.EtcdKeyGetRequest in project camel by apache.
the class EtcdKeysProducer method processGet.
private void processGet(EtcdClient client, String path, Exchange exchange) throws Exception {
EtcdKeyGetRequest request = client.get(path);
setRequestTimeout(request, exchange);
setRequestRecursive(request, exchange);
try {
exchange.getIn().setHeader(EtcdConstants.ETCD_NAMESPACE, getNamespace());
exchange.getIn().setBody(request.send().get());
} catch (TimeoutException e) {
throw new ExchangeTimedOutException(exchange, configuration.getTimeout());
}
}
use of mousio.etcd4j.requests.EtcdKeyGetRequest in project camel by apache.
the class EtcdServiceDiscovery method getServices.
protected List<ServiceDefinition> getServices(Predicate<EtcdServiceDefinition> filter) {
List<ServiceDefinition> servers = Collections.emptyList();
if (isRunAllowed()) {
try {
final EtcdConfiguration conf = getConfiguration();
final EtcdKeyGetRequest request = getClient().get(conf.getServicePath()).recursive();
if (conf.hasTimeout()) {
request.timeout(conf.getTimeout(), TimeUnit.SECONDS);
}
final EtcdKeysResponse response = request.send().get();
if (Objects.nonNull(response.node) && !response.node.nodes.isEmpty()) {
servers = response.node.nodes.stream().map(node -> node.value).filter(ObjectHelper::isNotEmpty).map(this::nodeFromString).filter(Objects::nonNull).filter(filter).sorted(EtcdServiceDefinition.COMPARATOR).collect(Collectors.toList());
}
} catch (Exception e) {
throw new RuntimeCamelException(e);
}
}
return servers;
}
use of mousio.etcd4j.requests.EtcdKeyGetRequest in project camel by apache.
the class EtcdWatchConsumer method watch.
private void watch() throws Exception {
if (!isRunAllowed()) {
return;
}
EtcdKeyGetRequest request = getClient().get(getPath()).waitForChange(index.get());
if (configuration.isRecursive()) {
request.recursive();
}
if (configuration.getTimeout() != null) {
request.timeout(configuration.getTimeout(), TimeUnit.MILLISECONDS);
}
request.send().addListener(this);
}
use of mousio.etcd4j.requests.EtcdKeyGetRequest in project vertx-zero by silentbalanceyh.
the class EtcdData method readNode.
private EtcdKeysResponse.EtcdNode readNode(final String path, final Function<String, EtcdKeyGetRequest> executor) {
return Fn.getJvm(null, () -> {
final EtcdKeyGetRequest request = executor.apply(path);
/**
* Timeout *
*/
if (-1 != this.timeout) {
request.timeout(this.timeout, TimeUnit.SECONDS);
}
final EtcdResponsePromise<EtcdKeysResponse> promise = request.send();
final EtcdKeysResponse response = promise.get();
return response.getNode();
}, path);
}
Aggregations