/** * Creates {@code Watch} to monitoring a prefix of keys in the KV store. * The underlying Consul client will be created with default options. * This maps to the <a href="https://www.consul.io/api/kv.html">/v1/kv/</a> API internally. * * @param keyPrefix the key * @param vertx the {@code Vertx} instance * @return the {@code Watch} instance */ static Watch<KeyValueList> keyPrefix(String keyPrefix, Vertx vertx) { return keyPrefix(keyPrefix, vertx, new ConsulClientOptions()); }
/** * Creates <code>Watch</code> to monitoring a prefix of keys in the KV store. * The underlying Consul client will be created with default options. * This maps to the <a href="https://www.consul.io/api/kv.html">/v1/kv/</a> API internally. * @param keyPrefix the key * @param vertx the <code>Vertx</code> instance * @return the <code>Watch</code> instance */ public static io.vertx.rxjava.ext.consul.Watch<KeyValueList> keyPrefix(String keyPrefix, io.vertx.rxjava.core.Vertx vertx) { io.vertx.rxjava.ext.consul.Watch<KeyValueList> ret = io.vertx.rxjava.ext.consul.Watch.newInstance(io.vertx.ext.consul.Watch.keyPrefix(keyPrefix, vertx.getDelegate()), io.vertx.lang.rx.TypeArg.unknown()); return ret; }
/** * Creates <code>Watch</code> to monitoring a prefix of keys in the KV store. * This maps to the <a href="https://www.consul.io/api/kv.html">/v1/kv/</a> API internally. * @param keyPrefix the key * @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<KeyValueList> keyPrefix(String keyPrefix, io.vertx.rxjava.core.Vertx vertx, ConsulClientOptions options) { io.vertx.rxjava.ext.consul.Watch<KeyValueList> ret = io.vertx.rxjava.ext.consul.Watch.newInstance(io.vertx.ext.consul.Watch.keyPrefix(keyPrefix, vertx.getDelegate(), options), io.vertx.lang.rx.TypeArg.unknown()); return ret; }
public static io.vertx.ext.consul.Watch<io.vertx.ext.consul.KeyValueList> keyPrefix(io.vertx.ext.consul.Watch<Object> j_receiver, java.lang.String keyPrefix, io.vertx.core.Vertx vertx, java.util.Map<String, Object> options) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.ext.consul.Watch.keyPrefix(keyPrefix, 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.ServiceList> services(io.vertx.ext.consul.Watch<Object> j_receiver, io.vertx.core.Vertx vertx, java.util.Map<String, Object> options) {
/** * Creates <code>Watch</code> to monitoring a prefix of keys in the KV store. * This maps to the <a href="https://www.consul.io/api/kv.html">/v1/kv/</a> API internally. * @param keyPrefix the key * @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<KeyValueList> keyPrefix(String keyPrefix, io.vertx.rxjava.core.Vertx vertx, ConsulClientOptions options) { io.vertx.rxjava.ext.consul.Watch<KeyValueList> ret = io.vertx.rxjava.ext.consul.Watch.newInstance(io.vertx.ext.consul.Watch.keyPrefix(keyPrefix, vertx.getDelegate(), options), io.vertx.lang.rx.TypeArg.unknown()); return ret; }
/** * Creates <code>Watch</code> to monitoring a prefix of keys in the KV store. * The underlying Consul client will be created with default options. * This maps to the <a href="https://www.consul.io/api/kv.html">/v1/kv/</a> API internally. * @param keyPrefix the key * @param vertx the <code>Vertx</code> instance * @return the <code>Watch</code> instance */ public static io.vertx.rxjava.ext.consul.Watch<KeyValueList> keyPrefix(String keyPrefix, io.vertx.rxjava.core.Vertx vertx) { io.vertx.rxjava.ext.consul.Watch<KeyValueList> ret = io.vertx.rxjava.ext.consul.Watch.newInstance(io.vertx.ext.consul.Watch.keyPrefix(keyPrefix, vertx.getDelegate()), io.vertx.lang.rx.TypeArg.unknown()); return ret; }
@Test public void testKeyPrefix() throws InterruptedException { StateConsumer<String> consumer = new StateConsumer<>(); String keyPrefix = ConsulContext.KEY_RW_PREFIX + randomAlphaString(10); String k1 = keyPrefix + randomAlphaString(10); String k2 = keyPrefix + randomAlphaString(10); String v1 = randomAlphaString(10); String v2 = randomAlphaString(10); assertTrue(getAsync(h -> ctx.writeClient().putValue(k1, v1, h))); Watch<KeyValueList> watch = Watch.keyPrefix(keyPrefix, vertx, ctx.readClientOptions()) .setHandler(kv -> { if (kv.succeeded()) { if (kv.nextResult().isPresent()) { consumer.consume(kv.nextResult().getList().stream().map(KeyValue::getValue).sorted().collect(Collectors.joining("/"))); } else { consumer.consume(EMPTY_MESSAGE); } } else { consumer.consume(kv.cause().getMessage()); } }) .start(); consumer.await(v1); assertTrue(getAsync(h -> ctx.writeClient().putValue(k2, v2, h))); consumer.await(Stream.of(v1, v2).sorted().collect(Collectors.joining("/"))); runAsync(h -> ctx.writeClient().deleteValues(keyPrefix, h)); consumer.await(EMPTY_MESSAGE); consumer.check(); watch.stop(); }