Record record2 = HttpEndpoint.createRecord("some-rest-api", "localhost", 8080, "/api");
@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 getHttpClient(JsonObject jsonFilter, Handler<AsyncResult<HttpClient>> handler) { HttpEndpoint.getClient(serviceDiscovery, jsonFilter, handler); }
@Test public void testPublicationAndConsumptionWithConfiguration(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.getClient(discovery, new JsonObject().put("name", "hello-service"), new JsonObject().put ("keepAlive", false), found -> { context.assertTrue(found.succeeded()); context.assertTrue(found.result() != null); HttpClient client = found.result(); client.getNow("/foo", response -> { context.assertEquals(response.statusCode(), 200); context.assertEquals(response.getHeader("connection"), "close"); response.bodyHandler(body -> { context.assertEquals(body.toString(), "hello"); ServiceDiscovery.releaseServiceObject(discovery, client); discovery.unpublish(published.getRegistration(), v -> async.complete()); }); }); }); }); }
@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()); }); }); }); }
HttpEndpoint.getClient(discovery, record -> record.getName().equalsIgnoreCase("my-http-service"), ar -> { HttpEndpoint.getWebClient(discovery, record -> record.getName().equalsIgnoreCase("my-http-service"), ar -> {
public void getHttpClient(Function<Record, Boolean> filter, JsonObject configuration, Handler<AsyncResult<HttpClient>> handler) { HttpEndpoint.getClient(serviceDiscovery, filter, configuration, handler); }
@Test public void testPublicationAndConsumptionWithConfiguration(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.getClient(discovery, new JsonObject().put("name", "hello-service"), new JsonObject().put ("keepAlive", false), found -> { context.assertTrue(found.succeeded()); context.assertTrue(found.result() != null); HttpClient client = found.result(); client.getNow("/foo", context.asyncAssertSuccess(response -> { context.assertEquals(response.statusCode(), 200); context.assertEquals(response.getHeader("connection"), "close"); response.bodyHandler(body -> { context.assertEquals(body.toString(), "hello"); ServiceDiscovery.releaseServiceObject(discovery, client); discovery.unpublish(published.getRegistration(), v -> async.complete()); }); })); }); }); }
@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()); }); }); }); }
HttpEndpoint.getClient(discovery, record -> record.getName().equalsIgnoreCase("my-http-service"), ar -> { HttpEndpoint.getWebClient(discovery, record -> record.getName().equalsIgnoreCase("my-http-service"), ar -> {
/** * Same as {@link io.vertx.rxjava.servicediscovery.types.HttpEndpoint#createRecord} but without metadata. * @param name the service name * @param host the host, must be public * @param port the port * @param root the root, if not set "/" is used * @return the created record */ public static Record createRecord(String name, String host, int port, String root) { Record ret = io.vertx.servicediscovery.types.HttpEndpoint.createRecord(name, host, port, root); return ret; }
public void getWebClient(JsonObject jsonFilter, JsonObject configuration, Handler<AsyncResult<WebClient>> handler) { HttpEndpoint.getWebClient(serviceDiscovery, jsonFilter, configuration, handler); } }
public void getHttpClient(Function<Record, Boolean> filter, Handler<AsyncResult<HttpClient>> handler) { HttpEndpoint.getClient(serviceDiscovery, filter, handler); }
/** * Same as {@link io.vertx.rxjava.servicediscovery.types.HttpEndpoint#createRecord} but without metadata, using the port 80 * and using "/" as root. * @param name the name * @param host the host * @return the created record */ public static Record createRecord(String name, String host) { Record ret = io.vertx.servicediscovery.types.HttpEndpoint.createRecord(name, host); return ret; }
public void getWebClient(Function<Record, Boolean> filter, JsonObject configuration, Handler<AsyncResult<WebClient>> handler) { HttpEndpoint.getWebClient(serviceDiscovery, filter, configuration, handler); }
public void getHttpClient(JsonObject jsonFilter, JsonObject configuration, Handler<AsyncResult<HttpClient>> handler) { HttpEndpoint.getClient(serviceDiscovery, jsonFilter, configuration, handler); }
/** * Same as {@link #createRecord(String, String, int, String, JsonObject)} but without metadata. * * @param name the service name * @param host the host, must be public * @param port the port * @param root the root, if not set "/" is used * @return the created record */ static Record createRecord(String name, String host, int port, String root) { return createRecord(name, host, port, root, null); }
public void getWebClient(JsonObject jsonFilter, Handler<AsyncResult<WebClient>> handler) { HttpEndpoint.getWebClient(serviceDiscovery, jsonFilter, handler); }
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) { io.vertx.servicediscovery.types.HttpEndpoint.getClient(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.core.http.HttpClient>>() { public void handle(io.vertx.core.AsyncResult<io.vertx.core.http.HttpClient> ar) { resultHandler.handle(ar.map(event -> io.vertx.core.impl.ConversionHelper.fromObject(event))); } } : null); } 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) {
/** * Same as {@link io.vertx.rxjava.servicediscovery.types.HttpEndpoint#createRecord} but without metadata. * @param name the service name * @param host the host, must be public * @param port the port * @param root the root, if not set "/" is used * @return the created record */ public static Record createRecord(String name, String host, int port, String root) { Record ret = io.vertx.servicediscovery.types.HttpEndpoint.createRecord(name, host, port, root); return ret; }