io.vertx.servicediscovery.ServiceReference Java Examples

The following examples show how to use io.vertx.servicediscovery.ServiceReference. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EventBusService.java    From vertx-service-discovery with Apache License 2.0 6 votes vote down vote up
/**
 * Lookup for a service record and if found, retrieve it and return the service object (used to consume the service).
 * This is a convenient method to avoid explicit lookup and then retrieval of the service. This method requires to
 * have the {@code clientClass} set with the expected set of client. This is important for usages not using Java so
 * you can pass the expected type.
 *
 * @param discovery     the service discovery
 * @param filter        the filter as json object
 * @param clientClass   the client class
 * @param conf          the configuration for message delivery
 * @param resultHandler the result handler
 * @param <T>           the type of the client class
 * @return {@code null} - do not use
 */
static <T> T getServiceProxyWithJsonFilter(ServiceDiscovery discovery,
                                           JsonObject filter,
                                           Class<T> clientClass,
                                           JsonObject conf,
                                           Handler<AsyncResult<T>> resultHandler) {
  discovery.getRecord(filter, ar -> {
    if (ar.failed()) {
      resultHandler.handle(Future.failedFuture(ar.cause()));
    } else {
      if (ar.result() == null) {
        resultHandler.handle(Future.failedFuture("Cannot find service matching with " + filter));
      } else {
        ServiceReference service = discovery.getReferenceWithConfiguration(ar.result(), conf);
        resultHandler.handle(Future.succeededFuture(service.getAs(clientClass)));
      }
    }
  });
  return null;
}
 
Example #2
Source File: HTTPEndpointExamples.java    From vertx-service-discovery with Apache License 2.0 6 votes vote down vote up
public void example2(ServiceDiscovery discovery) {
  // Get the record
  discovery.getRecord(new JsonObject().put("name", "some-http-service"), ar -> {
    if (ar.succeeded() && ar.result() != null) {
      // Retrieve the service reference
      ServiceReference reference = discovery.getReference(ar.result());
      // Retrieve the service object
      HttpClient client = reference.getAs(HttpClient.class);

      // You need to path the complete path
      client.get("/api/persons", response -> {

        // ...

        // Dont' forget to release the service
        reference.release();

      });
    }
  });
}
 
Example #3
Source File: HTTPEndpointExamples.java    From vertx-service-discovery with Apache License 2.0 6 votes vote down vote up
public void example2_webclient(ServiceDiscovery discovery) {
  // Get the record
  discovery.getRecord(new JsonObject().put("name", "some-http-service"), ar -> {
    if (ar.succeeded() && ar.result() != null) {
      // Retrieve the service reference
      ServiceReference reference = discovery.getReference(ar.result());
      // Retrieve the service object
      WebClient client = reference.getAs(WebClient.class);

      // You need to path the complete path
      client.get("/api/persons").send(
        response -> {

          // ...

          // Dont' forget to release the service
          reference.release();

        });
    }
  });
}
 
Example #4
Source File: MessageSourceExamples.java    From vertx-service-discovery with Apache License 2.0 6 votes vote down vote up
public void example2(ServiceDiscovery discovery) {
  // Get the record
  discovery.getRecord(new JsonObject().put("name", "some-message-source-service"), ar -> {
    if (ar.succeeded() && ar.result() != null) {
      // Retrieve the service reference
      ServiceReference reference = discovery.getReference(ar.result());
      // Retrieve the service object
      MessageConsumer<JsonObject> consumer = reference.getAs(MessageConsumer.class);

      // Attach a message handler on it
      consumer.handler(message -> {
        // message handler
        JsonObject payload = message.body();
      });
    }
  });
}
 
Example #5
Source File: RedisDataSourceExamples.java    From vertx-service-discovery with Apache License 2.0 6 votes vote down vote up
public void example2(ServiceDiscovery discovery) {
  // Get the record
  discovery.getRecord(
    new JsonObject().put("name", "some-redis-data-source-service"), ar -> {
      if (ar.succeeded() && ar.result() != null) {
        // Retrieve the service reference
        ServiceReference reference = discovery.getReference(ar.result());

        // Retrieve the service instance
        Redis client = reference.getAs(Redis.class);

        // ...

        // when done
        reference.release();
      }
    });
}
 
Example #6
Source File: GraphQLClient.java    From vertx-graphql-service-discovery with Apache License 2.0 6 votes vote down vote up
/**
 * Get the GraphQL service proxy that is associated with the provided service record.
 *
 * @param discovery     the service discovery instance
 * @param record        the service record of a published GraphQL service
 * @param resultHandler the result handler
 */
static void getSchemaProxy(ServiceDiscovery discovery, Record record,
                           Handler<AsyncResult<Queryable>> resultHandler) {
    Objects.requireNonNull(discovery, "Service discovery cannot be null");
    Objects.requireNonNull(record, "Record cannot be null");
    Objects.requireNonNull(resultHandler, "Schema proxy result handler cannot be null");

    if (!SERVICE_TYPE.equals(record.getType())) {
        resultHandler.handle(Future.failedFuture("Record '" + record.getName() +
                "' is of wrong type '" + record.getType() + "'. Expected: " + SERVICE_TYPE));
    } else if (!Status.UP.equals(record.getStatus())) {
        resultHandler.handle(Future.failedFuture("Record status indicates service '" + record.getName() +
                "' is: " + record.getStatus() + ". Expected: " + Status.UP));
    } else if (record.getRegistration() == null) {
        resultHandler.handle(Future.failedFuture("Record '" + record.getName() +
                "' has no service discovery registration"));
    } else {
        ServiceReference reference = discovery.getReference(record);
        Queryable queryable = reference.cached() == null ? reference.get() : reference.cached();
        reference.release();
        resultHandler.handle(Future.succeededFuture(queryable));
    }
}
 
Example #7
Source File: JDBCDataSourceExamples.java    From vertx-service-discovery with Apache License 2.0 6 votes vote down vote up
public void example2(ServiceDiscovery discovery) {
  // Get the record
  discovery.getRecord(
      new JsonObject().put("name", "some-data-source-service"),
      ar -> {
        if (ar.succeeded() && ar.result() != null) {
          // Retrieve the service reference
          ServiceReference reference = discovery.getReferenceWithConfiguration(
              ar.result(), // The record
              new JsonObject().put("username", "clement").put("password", "*****")); // Some additional metadata

          // Retrieve the service object
          JDBCClient client = reference.getAs(JDBCClient.class);

          // ...

          // when done
          reference.release();
        }
      });
}
 
Example #8
Source File: EventBusService.java    From vertx-service-discovery with Apache License 2.0 6 votes vote down vote up
/**
 * Lookup for a service record and if found, retrieve it and return the service object (used to consume the service).
 * This is a convenient method to avoid explicit lookup and then retrieval of the service. This method requires to
 * have the {@code clientClass} set with the expected set of client. This is important for usages not using Java so
 * you can pass the expected type.
 *
 * @param discovery     the service discovery
 * @param filter        the filter as json object
 * @param clientClass   the client class
 * @param resultHandler the result handler
 * @param <T>           the type of the client class
 * @return {@code null} - do not use
 */
static <T> T getServiceProxyWithJsonFilter(ServiceDiscovery discovery,
                                           JsonObject filter,
                                           Class<T> clientClass,
                                           Handler<AsyncResult<T>> resultHandler) {
  discovery.getRecord(filter, ar -> {
    if (ar.failed()) {
      resultHandler.handle(Future.failedFuture(ar.cause()));
    } else {
      if (ar.result() == null) {
        resultHandler.handle(Future.failedFuture("Cannot find service matching with " + filter));
      } else {
        ServiceReference service = discovery.getReference(ar.result());
        resultHandler.handle(Future.succeededFuture(service.getAs(clientClass)));
      }
    }
  });
  return null;
}
 
Example #9
Source File: EventBusService.java    From vertx-service-discovery with Apache License 2.0 6 votes vote down vote up
/**
 * Lookup for a service record and if found, retrieve it and return the service object (used to consume the service).
 * This is a convenient method to avoid explicit lookup and then retrieval of the service. This method requires to
 * have the {@code clientClass} set with the expected set of client. This is important for usages not using Java so
 * you can pass the expected type.
 *
 * @param discovery     the service discovery
 * @param filter        the filter
 * @param clientClass   the client class
 * @param conf          the configuration for message delivery
 * @param resultHandler the result handler
 * @param <T>           the type of the client class
 * @return {@code null} - do not use
 */
static <T> T getServiceProxy(ServiceDiscovery discovery,
                             Function<Record, Boolean> filter,
                             Class<T> clientClass,
                             JsonObject conf,
                             Handler<AsyncResult<T>> resultHandler) {
  discovery.getRecord(filter, ar -> {
    if (ar.failed()) {
      resultHandler.handle(Future.failedFuture(ar.cause()));
    } else {
      if (ar.result() == null) {
        resultHandler.handle(Future.failedFuture("Cannot find service matching with " + filter));
      } else {
        ServiceReference service = discovery.getReferenceWithConfiguration(ar.result(), conf);
        resultHandler.handle(Future.succeededFuture(service.getAs(clientClass)));
      }
    }
  });
  return null;
}
 
Example #10
Source File: MongoDataSourceExamples.java    From vertx-service-discovery with Apache License 2.0 6 votes vote down vote up
public void example2(ServiceDiscovery discovery) {
  // Get the record
  discovery.getRecord(
    new JsonObject().put("name", "some-data-source-service"),
    ar -> {
      if (ar.succeeded() && ar.result() != null) {
        // Retrieve the service reference
        ServiceReference reference = discovery.getReferenceWithConfiguration(
          ar.result(), // The record
          new JsonObject().put("username", "clement").put("password", "*****")); // Some additional metadata

        // Retrieve the service object
        MongoClient client = reference.get();

        // ...

        // when done
        reference.release();
      }
    });
}
 
Example #11
Source File: EventBusService.java    From vertx-service-discovery with Apache License 2.0 6 votes vote down vote up
/**
 * Lookup for a service record and if found, retrieve it and return the service object (used to consume the service).
 * This is a convenient method to avoid explicit lookup and then retrieval of the service. This method requires to
 * have the {@code clientClass} set with the expected set of client. This is important for usages not using Java so
 * you can pass the expected type.
 *
 * @param discovery     the service discovery
 * @param filter        the filter
 * @param clientClass   the client class
 * @param resultHandler the result handler
 * @param <T>           the type of the client class
 * @return {@code null} - do not use
 */
static <T> T getServiceProxy(ServiceDiscovery discovery,
                             Function<Record, Boolean> filter,
                             Class<T> clientClass,
                             Handler<AsyncResult<T>> resultHandler) {
  discovery.getRecord(filter, ar -> {
    if (ar.failed()) {
      resultHandler.handle(Future.failedFuture(ar.cause()));
    } else {
      if (ar.result() == null) {
        resultHandler.handle(Future.failedFuture("Cannot find service matching with " + filter));
      } else {
        ServiceReference service = discovery.getReference(ar.result());
        resultHandler.handle(Future.succeededFuture(service.getAs(clientClass)));
      }
    }
  });
  return null;
}
 
Example #12
Source File: DashboardVerticle.java    From microtrader with MIT License 6 votes vote down vote up
private Future<Void> retrieveAuditService() {
    Future<Void> future = Future.future();

    discovery.getRecord(new JsonObject().put("name", "audit"), ar -> {
        if (ar.failed()) {
            future.fail(ar.cause());
        } else if (ar.result() == null) {
            future.fail("Could not retrieve audit service");
        } else {
            ServiceReference reference = discovery.getReference(ar.result());
            this.root = reference.record().getLocation().getString("root");
            this.client = reference.get();
            future.complete();
        }
    });

    return future;
}
 
Example #13
Source File: EventBusService.java    From vertx-service-discovery with Apache License 2.0 6 votes vote down vote up
/**
 * Lookup for a service record and if found, retrieve it and return the service object (used to consume the service).
 * This is a convenient method to avoid explicit lookup and then retrieval of the service. A filter based on the
 * request interface is used.
 *
 * @param discovery     the service discovery instance
 * @param itf           the service interface
 * @param resultHandler the result handler
 * @param <T>           the service interface
 * @return {@code null}
 */
@GenIgnore // Java only
static <T> T getProxy(ServiceDiscovery discovery, Class<T> itf, Handler<AsyncResult<T>>
  resultHandler) {
  JsonObject filter = new JsonObject().put("service.interface", itf.getName());
  discovery.getRecord(filter, ar -> {
    if (ar.failed()) {
      resultHandler.handle(Future.failedFuture(ar.cause()));
    } else {
      if (ar.result() == null) {
        resultHandler.handle(Future.failedFuture("Cannot find service matching with " + filter));
      } else {
        ServiceReference service = discovery.getReference(ar.result());
        resultHandler.handle(Future.succeededFuture(service.get()));
      }
    }
  });
  return null;
}
 
Example #14
Source File: EventBusService.java    From vertx-service-discovery with Apache License 2.0 6 votes vote down vote up
/**
 * Lookup for a service record and if found, retrieve it and return the service object (used to consume the service).
 * This is a convenient method to avoid explicit lookup and then retrieval of the service. A filter based on the
 * request interface is used.
 *
 * @param discovery     the service discovery instance
 * @param itf           the service interface
 * @param conf          the configuration for message delivery
 * @param resultHandler the result handler
 * @param <T>           the service interface
 * @return {@code null}
 */
@GenIgnore // Java only
static <T> T getProxy(ServiceDiscovery discovery, Class<T> itf, JsonObject conf, Handler<AsyncResult<T>> resultHandler) {
  JsonObject filter = new JsonObject().put("service.interface", itf.getName());
  discovery.getRecord(filter, ar -> {
    if (ar.failed()) {
      resultHandler.handle(Future.failedFuture(ar.cause()));
    } else {
      if (ar.result() == null) {
        resultHandler.handle(Future.failedFuture("Cannot find service matching with " + filter));
      } else {
        ServiceReference service = discovery.getReferenceWithConfiguration(ar.result(), conf);
        resultHandler.handle(Future.succeededFuture(service.get()));
      }
    }
  });
  return null;
}
 
Example #15
Source File: RedisDataSourceTest.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
  Record record = RedisDataSource.createRecord("some-redis-data-source",
    new JsonObject().put("endpoint", "redis://localhost:6379"),
    new JsonObject().put("database", "some-raw-data"));

  discovery.publish(record, r -> {
  });
  await().until(() -> record.getRegistration() != null);

  AtomicReference<Record> found = new AtomicReference<>();
  discovery.getRecord(new JsonObject().put("name", "some-redis-data-source"), ar -> {
    found.set(ar.result());
  });

  await().until(() -> found.get() != null);
  ServiceReference service = discovery.getReference(found.get());
  Redis client = service.get();
  AtomicBoolean success = new AtomicBoolean();
  client.connect(connect -> {
    if (connect.succeeded()) {
      RedisConnection conn = connect.result();
      conn.send(Request.cmd(Command.PING), ar -> {
        if (ar.succeeded()) {
          client.close();
          success.set(ar.succeeded());
        }
      });
    }
  });

  await().untilAtomic(success, is(true));
  service.release();
  // Just there to be sure we can call it twice
  service.release();
}
 
Example #16
Source File: JDBCDataSourceTest.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws InterruptedException {
  JsonObject conf = new JsonObject()
      .put("driverclass", "org.hsqldb.jdbcDriver");

  Record record = JDBCDataSource.createRecord("some-hsql-db",
      new JsonObject().put("url", "jdbc:hsqldb:file:target/dumb-db;shutdown=true"),
      new JsonObject().put("database", "some-raw-data"));

  discovery.publish(record, (r) -> {
  });
  await().until(() -> record.getRegistration() != null);

  AtomicReference<Record> found = new AtomicReference<>();
  discovery.getRecord(new JsonObject().put("name", "some-hsql-db"), ar -> {
    found.set(ar.result());
  });

  await().until(() -> found.get() != null);

  ServiceReference service = discovery.getReferenceWithConfiguration(found.get(), conf);
  JDBCClient client = service.get();
  AtomicBoolean success = new AtomicBoolean();
  client.getConnection(ar -> {
    if (ar.succeeded()) {
      ar.result().close();
    }
    success.set(ar.succeeded());
  });

  await().untilAtomic(success, is(true));
  service.release();
  // Just there to be sure we can call it twice
  service.release();
}
 
Example #17
Source File: HttpEndpointTest.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
@Test
public void testPublicationAndConsumptionAsWebClient(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();
      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);

      client.get("/foo")
        .send(response -> {
          if (response.failed()) {
            context.fail(response.cause());
          } else {
            HttpResponse<Buffer> resp = response.result();
            context.assertEquals(resp.statusCode(), 200);
            context.assertEquals(resp.body().toString(), "hello");
            reference.release();

            discovery.unpublish(published.getRegistration(), v -> async.complete());
          }
        });
    });
  });
}
 
Example #18
Source File: MessageSourceTest.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws InterruptedException {
  Random random = new Random();
  vertx.setPeriodic(10, l -> {
    vertx.eventBus().publish("data", random.nextDouble());
  });

  Record record = MessageSource.createRecord("Hello", "data");

  discovery.publish(record, (r) -> {
  });
  await().until(() -> record.getRegistration() != null);

  AtomicReference<Record> found = new AtomicReference<>();
  discovery.getRecord(new JsonObject().put("name", "Hello"), ar -> {
    found.set(ar.result());
  });

  await().until(() -> found.get() != null);

  ServiceReference service = discovery.getReference(found.get());
  MessageConsumer<Double> consumer = service.get();

  List<Double> data = new ArrayList<>();
  consumer.handler(message -> {
    data.add(message.body());
  });
  await().until(() -> !data.isEmpty());
  service.release();
  int size = data.size();
  Thread.sleep(500);
  assertThat(data.size()).isEqualTo(size);

  // Just there to be sure we can call it twice
  service.release();
}
 
Example #19
Source File: MongoDataSourceTest.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws InterruptedException {
  Record record = MongoDataSource.createRecord("some-mongo-db",
    new JsonObject().put("connection_string", "mongodb://localhost:12345"),
    new JsonObject().put("database", "some-raw-data"));

  discovery.publish(record, (r) -> {
  });
  await().until(() -> record.getRegistration() != null);

  AtomicReference<Record> found = new AtomicReference<>();
  discovery.getRecord(new JsonObject().put("name", "some-mongo-db"), ar -> {
    found.set(ar.result());
  });

  await().until(() -> found.get() != null);

  ServiceReference service = discovery.getReference(found.get());
  MongoClient client = service.get();
  AtomicBoolean success = new AtomicBoolean();
  client.getCollections(ar -> {
    success.set(ar.succeeded());
  });

  await().untilAtomic(success, is(true));
  service.release();
  // Just there to be sure we can call it twice
  service.release();
}
 
Example #20
Source File: HttpEndpointTest.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
@Test
public void testPublicationAndConsumption(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();
      ServiceReference reference = discovery.getReference(match);
      context.assertEquals(reference.record().getLocation().getString("endpoint"), "http://localhost:8080/foo");
      context.assertFalse(reference.record().getLocation().getBoolean("ssl"));
      HttpClient client = reference.get();
      HttpClient client2 = reference.get();
      context.assertTrue(client == client2);

      client.get("/foo", context.asyncAssertSuccess(response -> {
        context.assertEquals(response.statusCode(), 200);
        response.bodyHandler(body -> {
          context.assertEquals(body.toString(), "hello");

          reference.release();

          discovery.unpublish(published.getRegistration(), v -> {
            async.complete();
          });
        });
      }));
    });
  });
}
 
Example #21
Source File: HttpEndpointImpl.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
@Override
public ServiceReference get(Vertx vertx, ServiceDiscovery discovery, Record record, JsonObject configuration) {
  Objects.requireNonNull(vertx);
  Objects.requireNonNull(record);
  Objects.requireNonNull(discovery);
  return new HttpEndpointReference(vertx, discovery, record, configuration);
}
 
Example #22
Source File: HttpEndpointTest.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
@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());
    });
  });
}
 
Example #23
Source File: HttpEndpointTest.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
@Test
public void testRecordCreation(TestContext testContext) {
  Record record = HttpEndpoint.createRecord("some-name", "123.456.789.111", 80, null);
  assertThat(record.getLocation().getString(Record.ENDPOINT)).isEqualTo("http://123.456.789.111:80/");

  record = HttpEndpoint.createRecord("some-name", "123.456.789.111", 80, "foo");
  assertThat(record.getLocation().getString(Record.ENDPOINT)).isEqualTo("http://123.456.789.111:80/foo");

  record = HttpEndpoint.createRecord("some-name", "123.456.789.111", 80, "foo", new JsonObject().put("language", "en"));
  assertThat(record.getLocation().getString(Record.ENDPOINT)).isEqualTo("http://123.456.789.111:80/foo");
  assertThat(record.getMetadata().getString("language")).isEqualTo("en");

  record = HttpEndpoint.createRecord("some-name", "acme.org");
  assertThat(record.getLocation().getString(Record.ENDPOINT)).isEqualTo("http://acme.org:80/");

  SelfSignedCertificate selfSignedCertificate = SelfSignedCertificate.create();
  vertx.createHttpServer(new HttpServerOptions()
    .setHost("127.0.0.1")
    .setSsl(true)
    .setKeyCertOptions(selfSignedCertificate.keyCertOptions())
  ).requestHandler(request -> {
    request.response().end(new JsonObject().put("url", request.absoluteURI()).encode());
  }).listen(0, testContext.asyncAssertSuccess(server -> {

    Record sslRecord = HttpEndpoint.createRecord("http-bin", true, "127.0.0.1", server.actualPort(), "/get", null);
    ServiceReference reference = discovery.getReferenceWithConfiguration(sslRecord, new HttpClientOptions()
      .setSsl(true)
      .setTrustAll(true)
      .setVerifyHost(false)
      .toJson());

    WebClient webClient = WebClient.wrap(reference.get());
    webClient.get("/get").as(BodyCodec.jsonObject()).send(testContext.asyncAssertSuccess(resp -> {
      assertEquals("https://127.0.0.1:" + server.actualPort() + "/get", resp.body().getString("url"));
    }));
  }));
}
 
Example #24
Source File: MyVerticle.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
private synchronized JsonArray getBindings(ServiceDiscovery discovery) {
  JsonArray array = new JsonArray();
  for (ServiceReference ref : discovery.bindings()) {
    array.add(ref.toString());
  }
  return array;
}
 
Example #25
Source File: GraphQLServiceImplTest.java    From vertx-graphql-service-discovery with Apache License 2.0 5 votes vote down vote up
@Test
public void should_Create_Service_Reference_With_Configuration() {
    ServiceReference reference = graphQLService.get(vertx, discovery, record, config);
    assertNotNull(reference);
    assertNull(reference.cached());
    Queryable serviceProxy = reference.get();
    assertNotNull(serviceProxy);
}
 
Example #26
Source File: MessageSourceImpl.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
@Override
public ServiceReference
  get(Vertx vertx, ServiceDiscovery discovery, Record record, JsonObject configuration) {

  Objects.requireNonNull(vertx);
  Objects.requireNonNull(record);
  Objects.requireNonNull(discovery);
  return new MessageSourceReference(vertx, discovery, record);
}
 
Example #27
Source File: MongoDataSourceImpl.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
@Override
public ServiceReference get(Vertx vertx, ServiceDiscovery discovery, Record record, JsonObject configuration) {
  Objects.requireNonNull(vertx);
  Objects.requireNonNull(record);
  Objects.requireNonNull(discovery);
  return new MongoServiceReference(vertx, discovery, record, configuration);
}
 
Example #28
Source File: RedisDataSourceImpl.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
@Override
public ServiceReference get(Vertx vertx, ServiceDiscovery discovery, Record record, JsonObject configuration) {
  Objects.requireNonNull(vertx);
  Objects.requireNonNull(record);
  Objects.requireNonNull(discovery);
  return new RedisServiceReference(vertx, discovery, record, configuration);
}
 
Example #29
Source File: EventBusServiceImpl.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
@Override
public ServiceReference get(Vertx vertx, ServiceDiscovery discovery, Record record, JsonObject
  configuration) {
  Objects.requireNonNull(vertx);
  Objects.requireNonNull(record);
  Objects.requireNonNull(discovery);
  return new EventBusServiceReference(vertx, discovery, record, configuration);
}
 
Example #30
Source File: JDBCDataSourceImpl.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
@Override
public ServiceReference get(Vertx vertx, ServiceDiscovery discovery, Record record, JsonObject configuration) {
  Objects.requireNonNull(vertx);
  Objects.requireNonNull(record);
  Objects.requireNonNull(discovery);
  return new JdbcServiceReference(vertx, discovery, record, configuration);
}