Java Code Examples for io.vertx.servicediscovery.ServiceDiscovery#getReference()

The following examples show how to use io.vertx.servicediscovery.ServiceDiscovery#getReference() . 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: 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 2
Source File: ServiceDiscoveryExamples.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
public void example5(ServiceDiscovery discovery, Record record1, Record record2) {
  ServiceReference reference1 = discovery.getReference(record1);
  ServiceReference reference2 = discovery.getReference(record2);

  // Then, gets the service object, the returned type depends on the service type:
  // For http endpoint:
  HttpClient client = reference1.getAs(HttpClient.class);
  // For message source
  MessageConsumer consumer = reference2.getAs(MessageConsumer.class);

  // When done with the service
  reference1.release();
  reference2.release();
}