@Override public void start() { Router router = Router.router(vertx); router.get("/").handler(this::invoke); // Retrieve the service discovery ServiceDiscovery.create(vertx, discovery -> // Retrieve a web client HttpEndpoint.getWebClient(discovery, svc -> svc.getName().equals("vertx-greeting"), ar -> { if (ar.failed()) { System.out.println("D'oh the service is not available"); } else { client = ar.result(); vertx.createHttpServer().requestHandler(router).listen(8080); } })); }
public void getWebClient(Function<Record, Boolean> filter, JsonObject configuration, Handler<AsyncResult<WebClient>> handler) { HttpEndpoint.getWebClient(serviceDiscovery, filter, configuration, handler); }
public void getWebClient(JsonObject jsonFilter, Handler<AsyncResult<WebClient>> handler) { HttpEndpoint.getWebClient(serviceDiscovery, jsonFilter, handler); }
public void getWebClient(JsonObject jsonFilter, JsonObject configuration, Handler<AsyncResult<WebClient>> handler) { HttpEndpoint.getWebClient(serviceDiscovery, jsonFilter, configuration, handler); } }
public void getWebClient(Function<Record, Boolean> filter, Handler<AsyncResult<WebClient>> handler) { HttpEndpoint.getWebClient(serviceDiscovery, filter, handler); }
public static void getWebClient(io.vertx.servicediscovery.types.HttpEndpoint j_receiver, io.vertx.servicediscovery.ServiceDiscovery discovery, java.util.function.Function<java.util.Map<String, Object>, java.lang.Boolean> filter, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.ext.web.client.WebClient>> resultHandler) { io.vertx.servicediscovery.types.HttpEndpoint.getWebClient(discovery, filter != null ? new java.util.function.Function<io.vertx.servicediscovery.Record, java.lang.Boolean>() { public java.lang.Boolean apply(io.vertx.servicediscovery.Record t) { java.util.Map<String, Object> o = t != null ? io.vertx.core.impl.ConversionHelper.fromJsonObject(t.toJson()) : null; java.lang.Boolean p = filter.apply(o); return p; } } : null, resultHandler != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.ext.web.client.WebClient>>() { public void handle(io.vertx.core.AsyncResult<io.vertx.ext.web.client.WebClient> ar) { resultHandler.handle(ar.map(event -> io.vertx.core.impl.ConversionHelper.fromObject(event))); } } : null); } public static void getClient(io.vertx.servicediscovery.types.HttpEndpoint j_receiver, io.vertx.servicediscovery.ServiceDiscovery discovery, java.util.function.Function<java.util.Map<String, Object>, java.lang.Boolean> filter, java.util.Map<String, Object> conf, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.core.http.HttpClient>> resultHandler) {
public static void getWebClient(io.vertx.servicediscovery.types.HttpEndpoint j_receiver, io.vertx.servicediscovery.ServiceDiscovery discovery, java.util.Map<String, Object> filter, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.ext.web.client.WebClient>> resultHandler) { io.vertx.servicediscovery.types.HttpEndpoint.getWebClient(discovery, filter != null ? io.vertx.core.impl.ConversionHelper.toJsonObject(filter) : null, resultHandler != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.ext.web.client.WebClient>>() { public void handle(io.vertx.core.AsyncResult<io.vertx.ext.web.client.WebClient> ar) { resultHandler.handle(ar.map(event -> io.vertx.core.impl.ConversionHelper.fromObject(event))); } } : null); } public static void getClient(io.vertx.servicediscovery.types.HttpEndpoint j_receiver, io.vertx.servicediscovery.ServiceDiscovery discovery, java.util.Map<String, Object> filter, java.util.Map<String, Object> conf, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.core.http.HttpClient>> resultHandler) {
private Future<WebClient> retrieveAuditService() { Future<WebClient> future = Future.future(); HttpEndpoint.getWebClient(discovery, new JsonObject().put("name", "audit-service"), future); return future; }
/** * Convenient method that looks for a HTTP endpoint and provides the configured . The async result * is marked as failed is there are no matching services, or if the lookup fails. * @param discovery The service discovery instance * @param filter The filter, optional * @param resultHandler The result handler */ public static void getWebClient(io.vertx.rxjava.servicediscovery.ServiceDiscovery discovery, JsonObject filter, Handler<AsyncResult<io.vertx.rxjava.ext.web.client.WebClient>> resultHandler) { io.vertx.servicediscovery.types.HttpEndpoint.getWebClient(discovery.getDelegate(), filter, new Handler<AsyncResult<io.vertx.ext.web.client.WebClient>>() { public void handle(AsyncResult<io.vertx.ext.web.client.WebClient> ar) { if (ar.succeeded()) { resultHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.web.client.WebClient.newInstance(ar.result()))); } else { resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); }
/** * Convenient method that looks for a HTTP endpoint and provides the configured . The async result * is marked as failed is there are no matching services, or if the lookup fails. * @param discovery The service discovery instance * @param filter The filter * @param resultHandler The result handler */ public static void getWebClient(io.vertx.rxjava.servicediscovery.ServiceDiscovery discovery, Function<Record, Boolean> filter, Handler<AsyncResult<io.vertx.rxjava.ext.web.client.WebClient>> resultHandler) { io.vertx.servicediscovery.types.HttpEndpoint.getWebClient(discovery.getDelegate(), filter, new Handler<AsyncResult<io.vertx.ext.web.client.WebClient>>() { public void handle(AsyncResult<io.vertx.ext.web.client.WebClient> ar) { if (ar.succeeded()) { resultHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.web.client.WebClient.newInstance(ar.result()))); } else { resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); }
/** * Convenient method that looks for a HTTP endpoint and provides the configured . The async result * is marked as failed is there are no matching services, or if the lookup fails. * @param discovery The service discovery instance * @param filter The filter * @param resultHandler The result handler */ public static void getWebClient(io.vertx.rxjava.servicediscovery.ServiceDiscovery discovery, Function<Record, Boolean> filter, Handler<AsyncResult<io.vertx.rxjava.ext.web.client.WebClient>> resultHandler) { io.vertx.servicediscovery.types.HttpEndpoint.getWebClient(discovery.getDelegate(), filter, new Handler<AsyncResult<io.vertx.ext.web.client.WebClient>>() { public void handle(AsyncResult<io.vertx.ext.web.client.WebClient> ar) { if (ar.succeeded()) { resultHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.web.client.WebClient.newInstance(ar.result()))); } else { resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); }
public static void getWebClient(io.vertx.servicediscovery.types.HttpEndpoint j_receiver, io.vertx.servicediscovery.ServiceDiscovery discovery, java.util.function.Function<java.util.Map<String, Object>, java.lang.Boolean> filter, java.util.Map<String, Object> conf, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.ext.web.client.WebClient>> resultHandler) { io.vertx.servicediscovery.types.HttpEndpoint.getWebClient(discovery, filter != null ? new java.util.function.Function<io.vertx.servicediscovery.Record, java.lang.Boolean>() { public java.lang.Boolean apply(io.vertx.servicediscovery.Record t) { java.util.Map<String, Object> o = t != null ? io.vertx.core.impl.ConversionHelper.fromJsonObject(t.toJson()) : null; java.lang.Boolean p = filter.apply(o); return p; } } : null, conf != null ? io.vertx.core.impl.ConversionHelper.toJsonObject(conf) : null, resultHandler != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.ext.web.client.WebClient>>() { public void handle(io.vertx.core.AsyncResult<io.vertx.ext.web.client.WebClient> ar) { resultHandler.handle(ar.map(event -> io.vertx.core.impl.ConversionHelper.fromObject(event))); } } : null); } }
/** * Convenient method that looks for a HTTP endpoint and provides the configured . The async result * is marked as failed is there are no matching services, or if the lookup fails. This method accepts a * configuration for the HTTP client * @param discovery The service discovery instance * @param filter The filter, optional * @param conf the configuration of the client * @param resultHandler The result handler */ public static void getWebClient(io.vertx.rxjava.servicediscovery.ServiceDiscovery discovery, JsonObject filter, JsonObject conf, Handler<AsyncResult<io.vertx.rxjava.ext.web.client.WebClient>> resultHandler) { io.vertx.servicediscovery.types.HttpEndpoint.getWebClient(discovery.getDelegate(), filter, conf, new Handler<AsyncResult<io.vertx.ext.web.client.WebClient>>() { public void handle(AsyncResult<io.vertx.ext.web.client.WebClient> ar) { if (ar.succeeded()) { resultHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.web.client.WebClient.newInstance(ar.result()))); } else { resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); }
/** * Convenient method that looks for a HTTP endpoint and provides the configured . The async result * is marked as failed is there are no matching services, or if the lookup fails. * @param discovery The service discovery instance * @param filter The filter, optional * @param resultHandler The result handler */ public static void getWebClient(io.vertx.rxjava.servicediscovery.ServiceDiscovery discovery, JsonObject filter, Handler<AsyncResult<io.vertx.rxjava.ext.web.client.WebClient>> resultHandler) { io.vertx.servicediscovery.types.HttpEndpoint.getWebClient(discovery.getDelegate(), filter, new Handler<AsyncResult<io.vertx.ext.web.client.WebClient>>() { public void handle(AsyncResult<io.vertx.ext.web.client.WebClient> ar) { if (ar.succeeded()) { resultHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.web.client.WebClient.newInstance(ar.result()))); } else { resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); }
/** * Convenient method that looks for a HTTP endpoint and provides the configured . The async result * is marked as failed is there are no matching services, or if the lookup fails. This method accepts a * configuration for the HTTP client. * @param discovery The service discovery instance * @param filter The filter * @param conf the configuration of the client * @param resultHandler The result handler */ public static void getWebClient(io.vertx.rxjava.servicediscovery.ServiceDiscovery discovery, Function<Record, Boolean> filter, JsonObject conf, Handler<AsyncResult<io.vertx.rxjava.ext.web.client.WebClient>> resultHandler) { io.vertx.servicediscovery.types.HttpEndpoint.getWebClient(discovery.getDelegate(), filter, conf, new Handler<AsyncResult<io.vertx.ext.web.client.WebClient>>() { public void handle(AsyncResult<io.vertx.ext.web.client.WebClient> ar) { if (ar.succeeded()) { resultHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.web.client.WebClient.newInstance(ar.result()))); } else { resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); }
/** * Convenient method that looks for a HTTP endpoint and provides the configured . The async result * is marked as failed is there are no matching services, or if the lookup fails. This method accepts a * configuration for the HTTP client * @param discovery The service discovery instance * @param filter The filter, optional * @param conf the configuration of the client * @param resultHandler The result handler */ public static void getWebClient(io.vertx.rxjava.servicediscovery.ServiceDiscovery discovery, JsonObject filter, JsonObject conf, Handler<AsyncResult<io.vertx.rxjava.ext.web.client.WebClient>> resultHandler) { io.vertx.servicediscovery.types.HttpEndpoint.getWebClient(discovery.getDelegate(), filter, conf, new Handler<AsyncResult<io.vertx.ext.web.client.WebClient>>() { public void handle(AsyncResult<io.vertx.ext.web.client.WebClient> ar) { if (ar.succeeded()) { resultHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.web.client.WebClient.newInstance(ar.result()))); } else { resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); }
/** * Convenient method that looks for a HTTP endpoint and provides the configured . The async result * is marked as failed is there are no matching services, or if the lookup fails. This method accepts a * configuration for the HTTP client. * @param discovery The service discovery instance * @param filter The filter * @param conf the configuration of the client * @param resultHandler The result handler */ public static void getWebClient(io.vertx.rxjava.servicediscovery.ServiceDiscovery discovery, Function<Record, Boolean> filter, JsonObject conf, Handler<AsyncResult<io.vertx.rxjava.ext.web.client.WebClient>> resultHandler) { io.vertx.servicediscovery.types.HttpEndpoint.getWebClient(discovery.getDelegate(), filter, conf, new Handler<AsyncResult<io.vertx.ext.web.client.WebClient>>() { public void handle(AsyncResult<io.vertx.ext.web.client.WebClient> ar) { if (ar.succeeded()) { resultHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.web.client.WebClient.newInstance(ar.result()))); } else { resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); }
private Future<Void> retrieveAuditService() { return Future.future(future -> { HttpEndpoint.getWebClient(discovery, new JsonObject().put("name", "audit"), client -> { this.client = client.result(); future.handle(client.map((Void)null)); }); }); }
public static void getWebClient(io.vertx.servicediscovery.types.HttpEndpoint j_receiver, io.vertx.servicediscovery.ServiceDiscovery discovery, java.util.Map<String, Object> filter, java.util.Map<String, Object> conf, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.ext.web.client.WebClient>> resultHandler) { io.vertx.servicediscovery.types.HttpEndpoint.getWebClient(discovery, filter != null ? io.vertx.core.impl.ConversionHelper.toJsonObject(filter) : null, conf != null ? io.vertx.core.impl.ConversionHelper.toJsonObject(conf) : null, resultHandler != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.ext.web.client.WebClient>>() { public void handle(io.vertx.core.AsyncResult<io.vertx.ext.web.client.WebClient> ar) { resultHandler.handle(ar.map(event -> io.vertx.core.impl.ConversionHelper.fromObject(event))); } } : null); } public static void getClient(io.vertx.servicediscovery.types.HttpEndpoint j_receiver, io.vertx.servicediscovery.ServiceDiscovery discovery, java.util.function.Function<java.util.Map<String, Object>, java.lang.Boolean> filter, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.core.http.HttpClient>> resultHandler) {
@Test public void testPublicationAndConsumptionWithConfigurationAsWebClient(TestContext context) { Async async = context.async(); // Publish the service Record record = HttpEndpoint.createRecord("hello-service", "localhost", 8080, "/foo"); discovery.publish(record, rec -> { Record published = rec.result(); HttpEndpoint.getWebClient(discovery, new JsonObject().put("name", "hello-service"), new JsonObject().put("keepAlive", false), found -> { context.assertTrue(found.succeeded()); context.assertTrue(found.result() != null); WebClient client = found.result(); client.get("/foo").send(ar -> { if (ar.failed()) { context.fail(ar.cause()); } HttpResponse<Buffer> response = ar.result(); context.assertEquals(response.statusCode(), 200); context.assertEquals(response.getHeader("connection"), "close"); context.assertEquals(response.body().toString(), "hello"); ServiceDiscovery.releaseServiceObject(discovery, client); discovery.unpublish(published.getRegistration(), v -> async.complete()); }); }); }); }