discovery.unpublish(record1.getRegistration(), ar -> { if (ar.succeeded()) { System.out.println("\"" + record1.getName() + "\" successfully unpublished");
/** * Un-publishes a record. * @param id the registration id * @param resultHandler handler called when the operation has completed (successfully or not). */ public void unpublish(String id, Handler<AsyncResult<Void>> resultHandler) { delegate.unpublish(id, resultHandler); }
/** * {@inheritDoc} */ @Override public void unpublish(String id, Handler<AsyncResult<Void>> resultHandler) { unmanagedDiscoveryInstance.unpublish(id, resultHandler); }
/** * Un-publishes a record. * @param id the registration id * @param resultHandler handler called when the operation has completed (successfully or not). */ public void unpublish(String id, Handler<AsyncResult<Void>> resultHandler) { delegate.unpublish(id, resultHandler); }
public void unpublish(Record record, Handler<AsyncResult<Void>> handler) { serviceDiscovery.unpublish(record.getRegistration(), handler); }
/** * Unpublish a GraphQL schema that was previously published. * * @param registration the information of the schema to unpublish * @param resultHandler the result handler */ static void unpublish(SchemaRegistration registration, Handler<AsyncResult<Void>> resultHandler) { Objects.requireNonNull(registration, "Schema registration cannot be null"); Objects.requireNonNull(resultHandler, "Un-publication result handler cannot be null"); registration.getDiscovery().unpublish(registration.getRecord().getRegistration(), rh -> { if (rh.succeeded()) { registration.unregisterServiceProxy(); resultHandler.handle(Future.succeededFuture()); } else { resultHandler.handle(Future.failedFuture(rh.cause())); } }); } }
private void deleteService(final ServiceDiscovery discovery, final Set<String> ids) { // Delete service from current zero system. Observable.fromIterable(ids) .subscribe(id -> { final String item = ID_MAP.get(id); discovery.unpublish(item, result -> { if (result.succeeded()) { // Delete successfully final Record record = REGISTRITIONS.get(id); this.successLog(record); // Sync deleted REGISTRITIONS.remove(id); ID_MAP.remove(id); // Remove from Set REGISTRY.remove(id); } else { LOGGER.info(Info.REG_FAILURE, result.cause().getMessage(), "Delete"); } }); }); }
private void deleteService(final ServiceDiscovery discovery, final Set<String> ids) { // Delete service from current zero system. Observable.fromIterable(ids) .subscribe(id -> { final String item = ID_MAP.get(id); discovery.unpublish(item, result -> { if (result.succeeded()) { // Delete successfully final Record record = REGISTRITIONS.get(id); this.successLog(record); // Sync deleted REGISTRITIONS.remove(id); ID_MAP.remove(id); // Remove from Set REGISTRY.remove(id); } else { LOGGER.info(Info.REG_FAILURE, result.cause().getMessage(), "Delete"); } }); }); }
private void unpublish(RoutingContext routingContext) { String uuid = routingContext.request().getParam("uuid"); discovery.unpublish(uuid, ar -> { if (ar.failed()) { routingContext.fail(ar.cause()); } else { routingContext.response().setStatusCode(204).end(); } }); }
private void unpublish(RoutingContext routingContext) { String uuid = routingContext.request().getParam("uuid"); discovery.unpublish(uuid, ar -> { if (ar.failed()) { routingContext.fail(ar.cause()); } else { routingContext.response().setStatusCode(204).end(); } }); }
@Override public void stop(Future<Void> future) throws Exception { List<Future> futures = new ArrayList<>(); for (Record record : registeredRecords) { Future<Void> unregistrationFuture = Future.future(); futures.add(unregistrationFuture); discovery.unpublish(record.getRegistration(), unregistrationFuture); } if (futures.isEmpty()) { discovery.close(); future.complete(); } else { CompositeFuture composite = CompositeFuture.all(futures); composite.setHandler(ar -> { discovery.close(); if (ar.failed()) { future.fail(ar.cause()); } else { future.complete(); } }); } } }
@Override public void stop(Future<Void> future) throws Exception { // In current design, the publisher is responsible for removing the service List<Future> futures = new ArrayList<>(); registeredRecords.forEach(record -> { Future<Void> cleanupFuture = Future.future(); futures.add(cleanupFuture); discovery.unpublish(record.getRegistration(), cleanupFuture.completer()); }); if (futures.isEmpty()) { discovery.close(); future.complete(); } else { CompositeFuture.all(futures) .setHandler(ar -> { discovery.close(); if (ar.failed()) { future.fail(ar.cause()); } else { future.complete(); } }); } } }
@Test public void testThatWeGetThePublishedServices() { HelloService svc = new HelloServiceImpl("stuff"); ProxyHelper.registerService(HelloService.class, vertx, svc, "address"); Record record = new Record() .setName("Hello") .setLocation(new JsonObject().put(Record.ENDPOINT, "address")); discovery.publish(record, (r) -> { }); await().until(() -> record.getRegistration() != null); Restafari.Response response = get("/discovery"); JsonArray services = new JsonArray(response.asString()); assertThat(services.size()).isEqualTo(1); Record rec = new Record(services.getJsonObject(0)); assertThat(rec.getStatus()).isEqualTo(Status.UP); assertThat(rec.getRegistration()).isNotNull(); assertThat(rec.getName()).isEqualTo("Hello"); AtomicBoolean done = new AtomicBoolean(); discovery.unpublish(record.getRegistration(), ar -> done.set(true)); await().untilAtomic(done, is(true)); response = get("/discovery"); services = new JsonArray(response.asString()); assertThat(services.size()).isEqualTo(0); }
@Test public void testThatWeGetThePublishedServices() { HelloService svc = new HelloServiceImpl("stuff"); ProxyHelper.registerService(HelloService.class, vertx, svc, "address"); Record record = new Record() .setName("Hello") .setLocation(new JsonObject().put(Record.ENDPOINT, "address")); discovery.publish(record, (r) -> { }); await().until(() -> record.getRegistration() != null); Restafari.Response response = get("/discovery"); JsonArray services = new JsonArray(response.asString()); assertThat(services.size()).isEqualTo(1); Record rec = new Record(services.getJsonObject(0)); assertThat(rec.getStatus()).isEqualTo(Status.UP); assertThat(rec.getRegistration()).isNotNull(); assertThat(rec.getName()).isEqualTo("Hello"); AtomicBoolean done = new AtomicBoolean(); discovery.unpublish(record.getRegistration(), ar -> done.set(true)); await().untilAtomic(done, is(true)); response = get("/discovery"); services = new JsonArray(response.asString()); assertThat(services.size()).isEqualTo(0); }
@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()); }); }); }); }
@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()); }); }); }); }
@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 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 testAutoCloseable(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(); discovery.getRecord(new JsonObject().put("name", "hello-service"), found -> { context.assertTrue(found.succeeded()); context.assertTrue(found.result() != null); Record match = found.result(); try (ServiceReference reference = discovery.getReference(match)) { context.assertEquals(reference.record().getLocation().getString("endpoint"), "http://localhost:8080/foo"); context.assertFalse(reference.record().getLocation().getBoolean("ssl")); WebClient client = reference.getAs(WebClient.class); WebClient client2 = reference.cachedAs(WebClient.class); context.assertTrue(client == client2); } catch (Exception e) { context.fail(e); } discovery.unpublish(published.getRegistration(), v -> async.complete()); }); }); }
@Test public void testAutoCloseable(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(); discovery.getRecord(new JsonObject().put("name", "hello-service"), found -> { context.assertTrue(found.succeeded()); context.assertTrue(found.result() != null); Record match = found.result(); try (ServiceReference reference = discovery.getReference(match)) { context.assertEquals(reference.record().getLocation().getString("endpoint"), "http://localhost:8080/foo"); context.assertFalse(reference.record().getLocation().getBoolean("ssl")); WebClient client = reference.getAs(WebClient.class); WebClient client2 = reference.cachedAs(WebClient.class); context.assertTrue(client == client2); } catch (Exception e) { context.fail(e); } discovery.unpublish(published.getRegistration(), v -> async.complete()); }); }); }