/** * Creates {@code Watch} to monitoring the nodes providing the service. * The underlying Consul client will be created with default options. * This maps to the <a href="https://www.consul.io/docs/agent/http/health.html#health_service">/v1/health/service/<service></a> API internally. * * @param service the service name * @param vertx the {@code Vertx} instance * @return the {@code Watch} instance */ static Watch<ServiceEntryList> service(String service, Vertx vertx) { return service(service, vertx, new ConsulClientOptions()); }
/** * Creates <code>Watch</code> to monitoring the nodes providing the service. * This maps to the <a href="https://www.consul.io/docs/agent/http/health.html#health_service">/v1/health/service/<service></a> API internally. * @param service the service name * @param vertx the <code>Vertx</code> instance * @param options the options to create underlying Consul client * @return the <code>Watch</code> instance */ public static io.vertx.rxjava.ext.consul.Watch<ServiceEntryList> service(String service, io.vertx.rxjava.core.Vertx vertx, ConsulClientOptions options) { io.vertx.rxjava.ext.consul.Watch<ServiceEntryList> ret = io.vertx.rxjava.ext.consul.Watch.newInstance(io.vertx.ext.consul.Watch.service(service, vertx.getDelegate(), options), io.vertx.lang.rx.TypeArg.unknown()); return ret; }
public static io.vertx.ext.consul.Watch<io.vertx.ext.consul.ServiceEntryList> service(io.vertx.ext.consul.Watch<Object> j_receiver, java.lang.String service, io.vertx.core.Vertx vertx, java.util.Map<String, Object> options) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.ext.consul.Watch.service(service, vertx, options != null ? new io.vertx.ext.consul.ConsulClientOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(options)) : null)); } public static io.vertx.ext.consul.Watch<io.vertx.ext.consul.EventList> events(io.vertx.ext.consul.Watch<Object> j_receiver, java.lang.String event, io.vertx.core.Vertx vertx, java.util.Map<String, Object> options) {
/** * Creates <code>Watch</code> to monitoring the nodes providing the service. * This maps to the <a href="https://www.consul.io/docs/agent/http/health.html#health_service">/v1/health/service/<service></a> API internally. * @param service the service name * @param vertx the <code>Vertx</code> instance * @param options the options to create underlying Consul client * @return the <code>Watch</code> instance */ public static io.vertx.rxjava.ext.consul.Watch<ServiceEntryList> service(String service, io.vertx.rxjava.core.Vertx vertx, ConsulClientOptions options) { io.vertx.rxjava.ext.consul.Watch<ServiceEntryList> ret = io.vertx.rxjava.ext.consul.Watch.newInstance(io.vertx.ext.consul.Watch.service(service, vertx.getDelegate(), options), io.vertx.lang.rx.TypeArg.unknown()); return ret; }
/** * Creates <code>Watch</code> to monitoring the nodes providing the service. * The underlying Consul client will be created with default options. * This maps to the <a href="https://www.consul.io/docs/agent/http/health.html#health_service">/v1/health/service/<service></a> API internally. * @param service the service name * @param vertx the <code>Vertx</code> instance * @return the <code>Watch</code> instance */ public static io.vertx.rxjava.ext.consul.Watch<ServiceEntryList> service(String service, io.vertx.rxjava.core.Vertx vertx) { io.vertx.rxjava.ext.consul.Watch<ServiceEntryList> ret = io.vertx.rxjava.ext.consul.Watch.newInstance(io.vertx.ext.consul.Watch.service(service, vertx.getDelegate()), io.vertx.lang.rx.TypeArg.unknown()); return ret; }
/** * Creates <code>Watch</code> to monitoring the nodes providing the service. * The underlying Consul client will be created with default options. * This maps to the <a href="https://www.consul.io/docs/agent/http/health.html#health_service">/v1/health/service/<service></a> API internally. * @param service the service name * @param vertx the <code>Vertx</code> instance * @return the <code>Watch</code> instance */ public static io.vertx.rxjava.ext.consul.Watch<ServiceEntryList> service(String service, io.vertx.rxjava.core.Vertx vertx) { io.vertx.rxjava.ext.consul.Watch<ServiceEntryList> ret = io.vertx.rxjava.ext.consul.Watch.newInstance(io.vertx.ext.consul.Watch.service(service, vertx.getDelegate()), io.vertx.lang.rx.TypeArg.unknown()); return ret; }
@Test public void watchService() throws InterruptedException { StateConsumer<String> consumer = new StateConsumer<>(); ServiceOptions service = new ServiceOptions() .setCheckOptions(new CheckOptions() .setStatus(CheckStatus.PASSING) .setTtl("4s") .setName(randomAlphaString(10))) .setId(randomAlphaString(10)) .setName(randomAlphaString(10)); Watch<ServiceEntryList> watch = Watch.service(service.getName(), vertx, ctx.readClientOptions()) .setHandler(list -> { if (list.succeeded()) { consumer.consume(list.nextResult().getList() .stream().filter(s -> s.getService().getName().equals(service.getName())) .map(e -> e.getService().getName() + "/" + e.getChecks().stream() .filter(c -> c.getId().equals("service:" + service.getId())) .map(c -> c.getStatus().name()).findFirst().orElse("")) .findFirst().orElse("")); } }) .start(); consumer.await(""); runAsync(h -> ctx.writeClient().registerService(service, h)); consumer.await(service.getName() + "/" + CheckStatus.PASSING.name()); consumer.await(service.getName() + "/" + CheckStatus.CRITICAL.name()); consumer.check(); watch.stop(); runAsync(h -> ctx.writeClient().deregisterService(service.getId(), h)); }