@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); } })); }
@Override public void start() { ServiceDiscovery discovery = ServiceDiscovery.create(vertx, new ServiceDiscoveryOptions() .setAnnounceAddress("service-announce")
private Future<ServiceDiscovery> getServiceDiscovery(Vertx vertx) { Future<ServiceDiscovery> future = Future.future(); ServiceDiscovery.create(vertx, future::complete); return future; }
/** * Creates a new instance of {@link ServiceDiscovery} using the default configuration. * * @param vertx the vert.x instance * @return the created instance */ static ServiceDiscovery create(Vertx vertx) { return create(vertx, new ServiceDiscoveryOptions()); }
/** * Creates a new instance of {@link ServiceDiscovery} using the default configuration. * * @param vertx the vert.x instance * @return the created instance */ static ServiceDiscovery create(Vertx vertx) { return create(vertx, new ServiceDiscoveryOptions()); }
/** * Creates a new instance of {@link io.vertx.rxjava.servicediscovery.ServiceDiscovery} using the default configuration. * @param vertx the vert.x instance * @return the created instance */ public static io.vertx.rxjava.servicediscovery.ServiceDiscovery create(io.vertx.rxjava.core.Vertx vertx) { io.vertx.rxjava.servicediscovery.ServiceDiscovery ret = io.vertx.rxjava.servicediscovery.ServiceDiscovery.newInstance(io.vertx.servicediscovery.ServiceDiscovery.create(vertx.getDelegate())); return ret; }
/** * Creates an instance of {@link io.vertx.rxjava.servicediscovery.ServiceDiscovery}. * @param vertx the vert.x instance * @param options the discovery options * @return the created service discovery instance. */ public static io.vertx.rxjava.servicediscovery.ServiceDiscovery create(io.vertx.rxjava.core.Vertx vertx, ServiceDiscoveryOptions options) { io.vertx.rxjava.servicediscovery.ServiceDiscovery ret = io.vertx.rxjava.servicediscovery.ServiceDiscovery.newInstance(io.vertx.servicediscovery.ServiceDiscovery.create(vertx.getDelegate(), options)); return ret; }
/** * Creates an instance of {@link io.vertx.rxjava.servicediscovery.ServiceDiscovery}. * @param vertx the vert.x instance * @param options the discovery options * @return the created service discovery instance. */ public static io.vertx.rxjava.servicediscovery.ServiceDiscovery create(io.vertx.rxjava.core.Vertx vertx, ServiceDiscoveryOptions options) { io.vertx.rxjava.servicediscovery.ServiceDiscovery ret = io.vertx.rxjava.servicediscovery.ServiceDiscovery.newInstance(io.vertx.servicediscovery.ServiceDiscovery.create(vertx.getDelegate(), options)); return ret; }
/** * Creates a new instance of {@link io.vertx.rxjava.servicediscovery.ServiceDiscovery} using the default configuration. * @param vertx the vert.x instance * @return the created instance */ public static io.vertx.rxjava.servicediscovery.ServiceDiscovery create(io.vertx.rxjava.core.Vertx vertx) { io.vertx.rxjava.servicediscovery.ServiceDiscovery ret = io.vertx.rxjava.servicediscovery.ServiceDiscovery.newInstance(io.vertx.servicediscovery.ServiceDiscovery.create(vertx.getDelegate())); return ret; }
public static io.vertx.servicediscovery.ServiceDiscovery create(io.vertx.servicediscovery.ServiceDiscovery j_receiver, io.vertx.core.Vertx vertx, java.util.Map<String, Object> options) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.servicediscovery.ServiceDiscovery.create(vertx, options != null ? new io.vertx.servicediscovery.ServiceDiscoveryOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(options)) : null)); } public static io.vertx.servicediscovery.ServiceDiscovery create(io.vertx.servicediscovery.ServiceDiscovery j_receiver, io.vertx.core.Vertx vertx, java.util.Map<String, Object> options, io.vertx.core.Handler<io.vertx.servicediscovery.ServiceDiscovery> completionHandler) {
public ServiceJet connect(final Vertx vertx) { this.discovery = ServiceDiscovery.create(vertx); final String name = this.options.getHost() + this.options.getPort(); this.breaker = CircuitBreaker.create(name, vertx, OPTIONS); return this; }
public static io.vertx.servicediscovery.ServiceDiscovery create(io.vertx.servicediscovery.ServiceDiscovery j_receiver, io.vertx.core.Vertx vertx, java.util.Map<String, Object> options, io.vertx.core.Handler<io.vertx.servicediscovery.ServiceDiscovery> completionHandler) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.servicediscovery.ServiceDiscovery.create(vertx, options != null ? new io.vertx.servicediscovery.ServiceDiscoveryOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(options)) : null, completionHandler != null ? event -> completionHandler.handle(io.vertx.core.impl.ConversionHelper.fromObject(event)) : null)); } public static void releaseServiceObject(io.vertx.servicediscovery.ServiceDiscovery j_receiver, io.vertx.servicediscovery.ServiceDiscovery discovery, java.lang.Object svcObject) {
@Test public void testHttpImport() { services.add(buildService("172.17.0.2", "web", "web", new String[]{"rails", "http-endpoint"}, 80, "passing")); discovery = ServiceDiscovery.create(vertx) .registerServiceImporter(new ConsulServiceImporter(), new JsonObject().put("host", "localhost").put("port", 5601)); await().until(() -> getAllRecordsBlocking().size() > 0); List<Record> list = getAllRecordsBlocking(); assertThat(list).hasSize(1); assertThat(list.get(0).getType()).isEqualTo(HttpEndpoint.TYPE); assertThat(list.get(0).getLocation().getString("endpoint")).isEqualTo("http://172.17.0.2:80"); }
@Before public void setUp() { vertx = Vertx.vertx(); options = new ServiceDiscoveryOptions().setName("my-schema-discovery"); discovery = ServiceDiscovery.create(vertx, options); }
@Test public void testImportServicesWithWarningStatusThreshold() { services.add(buildService("10.1.10.12", "redis", "redis", null, 8000, "passing")); services.add(buildService("10.1.10.12", "warning", "warning", null, 8001, "warning")); discovery = ServiceDiscovery.create(vertx) .registerServiceImporter(new ConsulServiceImporter(), new JsonObject().put("host", "localhost").put("port", 5601).put("up_threshold", "warning")); await().until(() -> getAllRecordsBlocking().size() > 0); List<Record> list = getAllRecordsBlocking(); assertThat(list).hasSize(2); }
@Test public void testImportServicesWithWarningStatusThreshold() { services.add(buildService("10.1.10.12", "redis", "redis", null, 8000, "passing")); services.add(buildService("10.1.10.12", "warning", "warning", null, 8001, "warning")); discovery = ServiceDiscovery.create(vertx) .registerServiceImporter(new ConsulServiceImporter(), new JsonObject().put("host", "localhost").put("port", 5601).put("up_threshold", "warning")); await().until(() -> getAllRecordsBlocking().size() > 0); List<Record> list = getAllRecordsBlocking(); assertThat(list).hasSize(2); }
@Test public void testServiceAvailability_OK() { ServiceDiscovery discovery = ServiceDiscovery.create(vertx); AtomicBoolean done = new AtomicBoolean(); discovery.publish(HttpEndpoint.createRecord("my-service", "localhost"), ar -> { done.set(ar.succeeded()); }); await().untilAtomic(done, is(true)); registerServiceProcedure(discovery); get(200); }
@Test public void testServiceAvailability_KO() { ServiceDiscovery discovery = ServiceDiscovery.create(vertx); registerServiceProcedure(discovery); get(503); }
@Test public void testDoesNotImportServicesWithWarningStatus() { // add 2 services so we can await on 1 being added below services.add(buildService("10.1.10.12", "redis", "redis", null, 8000, "passing")); services.add(buildService("10.1.10.12", "warning", "warning", null, 8001, "warning")); discovery = ServiceDiscovery.create(vertx) .registerServiceImporter(new ConsulServiceImporter(), new JsonObject().put("host", "localhost").put("port", 5601)); await().until(() -> getAllRecordsBlocking().size() > 0); List<Record> list = getAllRecordsBlocking(); assertThat(list).hasSize(1); }
@Test public void testAServiceBeingTwiceInConsul() { services.add(buildService("10.4.7.221", "ubuntu221:mysql:3306", "db", new String[] {"master", "backups"}, 32769, "passing")); services.add(buildService("10.4.7.220", "ubuntu220:mysql:3306", "db", new String[] {"master", "backups"}, 32771, "passing")); discovery = ServiceDiscovery.create(vertx) .registerServiceImporter(new ConsulServiceImporter(), new JsonObject().put("host", "localhost").put("port", 5601)); await().until(() -> getAllRecordsBlocking().size() > 0); List<Record> list = getAllRecordsBlocking(); assertThat(list).hasSize(2); }