/** * Creates {@code Watch} to monitoring the list of available nodes. * The underlying Consul client will be created with default options. * This maps to the <a href="https://www.consul.io/api/catalog.html#list-nodes">/v1/catalog/nodes</a> API internally. * * @param vertx the {@code Vertx} instance * @return the {@code Watch} instance */ static Watch<NodeList> nodes(Vertx vertx) { return new WatchImpl.Nodes(vertx, new ConsulClientOptions()); }
/** * Create a Consul client with default options. * * @param vertx the Vert.x instance * @return the client */ static ConsulClient create(Vertx vertx) { return new ConsulClientImpl(vertx, new ConsulClientOptions()); }
/** * Creates {@code Watch} to monitoring a specific key 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 key the key * @param vertx the {@code Vertx} instance * @return the {@code Watch} instance */ static Watch<KeyValue> key(String key, Vertx vertx) { return key(key, vertx, new ConsulClientOptions()); }
/** * Creates {@code Watch} to monitoring the custom user events. * The underlying Consul client will be created with default options. * This maps to the <a href="https://www.consul.io/docs/agent/http/event.html#event_list">/v1/event/list</a> API internally. * * @param event the event name * @param vertx the {@code Vertx} instance * @return the {@code Watch} instance */ static Watch<EventList> events(String event, Vertx vertx) { return events(event, vertx, new ConsulClientOptions()); }
@Override public void start() throws Exception { service = new ConsulServiceImpl(ConsulClient.create(vertx, new ConsulClientOptions(config()))); String address = config().getString("address"); if (address == null) { throw new IllegalStateException("address field must be specified in config for client verticle"); } messageConsumer = ProxyHelper.registerService(ConsulService.class, vertx, service, address); }
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) {
public static io.vertx.ext.consul.ConsulClient create(io.vertx.ext.consul.ConsulClient j_receiver, io.vertx.core.Vertx vertx, java.util.Map<String, Object> options) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.ext.consul.ConsulClient.create(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) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.ext.consul.Watch.services(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.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) {
public static io.vertx.ext.consul.Watch<io.vertx.ext.consul.KeyValue> key(io.vertx.ext.consul.Watch<Object> j_receiver, java.lang.String key, io.vertx.core.Vertx vertx, java.util.Map<String, Object> options) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.ext.consul.Watch.key(key, 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.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) {
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) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.ext.consul.Watch.events(event, 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.NodeList> nodes(io.vertx.ext.consul.Watch<Object> j_receiver, io.vertx.core.Vertx vertx, java.util.Map<String, Object> options) {
public static io.vertx.ext.consul.Watch<io.vertx.ext.consul.NodeList> nodes(io.vertx.ext.consul.Watch<Object> j_receiver, io.vertx.core.Vertx vertx, java.util.Map<String, Object> options) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.ext.consul.Watch.nodes(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.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) {
private void createMasterClient(ConsulTestNode node) { AtomicReference<ConsulTestNode> usedNode = new AtomicReference<>(node); masterClient = ConsulClient.create(vertx, new ConsulClientOptions().setAclToken(MASTER_TOKEN).setDc(TEST_DC).setHost(LOCALHOST).setPort(usedNode.get().httpPort()).setSsl(false)); vertx.setPeriodic(5000, l -> { if ((usedNode.get() == null || !usedNode.get().isRunning()) && masterClient != null) { masterClient.close(); masterClient = null; } }); } }
@Test public void fromEmptyJson() { ConsulClientOptions options = new ConsulClientOptions(new JsonObject()); assertEquals(options.getHost(), "localhost"); assertEquals(options.getPort(), 8500); }
@Test public void unknownHost(TestContext tc) { ConsulClient unknownHost = ctx.createClient(new ConsulClientOptions().setHost("unknownConsulHost")); tryClient(tc, unknownHost, "unknownConsulHost"); }
@Before public void setUp(TestContext tc) throws Exception { vertx = Vertx.vertx(); vertx.exceptionHandler(tc.exceptionHandler()); client = ConsulClient.create(vertx, new ConsulClientOptions().setPort(consulProcess.getHttpPort())); }
@Test public void timeout(TestContext tc) { SlowHttpServer slowConsul = new SlowHttpServer(vertx, 10000); ConsulClient client = ctx.createClient(new ConsulClientOptions().setPort(slowConsul.port()).setTimeout(1000)); client.agentInfo(tc.asyncAssertFailure(t -> { ctx.closeClient(client); slowConsul.close(); tc.assertTrue(t.getMessage().contains("The timeout period of 1000ms")); })); }
private void checkURI(URI uri, String host, int port, String dc, String acl) { ConsulClientOptions options = new ConsulClientOptions(uri); assertEquals(options.getHost(), host); assertEquals(options.getPort(), port); assertEquals(options.getDc(), dc); assertEquals(options.getAclToken(), acl); }
@Test public void toJson() { ConsulClientOptions options = new ConsulClientOptions() .setHost("host") .setPort(42) .setTimeout(33) .setUserAgent("ag") .setAclToken("tok") .setDc("d"); JsonObject json = options.toJson(); checkJson(options, json); }
private static ConsulClientOptions config(String token, boolean secure) { return new ConsulClientOptions() .setAclToken(token) .setDc(ConsulCluster.dc().getName()) .setHost("localhost") .setPort(secure ? ConsulCluster.getDefaultAgent().getHttpsPort() : ConsulCluster.getDefaultAgent().getHttpPort()) .setSsl(secure); }