本文整理汇总了Java中io.vertx.servicediscovery.ServiceReference类的典型用法代码示例。如果您正苦于以下问题:Java ServiceReference类的具体用法?Java ServiceReference怎么用?Java ServiceReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServiceReference类属于io.vertx.servicediscovery包,在下文中一共展示了ServiceReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
public Handler<RoutingContext> handle() {
return context -> {
// Run with circuit breaker
this.breaker.execute(future -> getEndPoints().setHandler(res -> {
if (res.succeeded()) {
final List<Record> records = res.result();
// Find the record hitted. ( Include Path variable such as /xx/yy/:zz/:xy )
final Record hitted = this.arithmetic.search(records, context);
// Complete actions.
if (null == hitted) {
// Service Not Found ( 404 )
reply404Error(context);
} else {
// Find record, dispatch request
final ServiceReference reference = this.discovery.getReference(hitted);
doRequest(context, reference);
}
future.complete();
} else {
// Future failed
future.fail(res.cause());
}
}));
};
}
示例2: retrieveAuditService
import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
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;
}
示例3: example2
import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
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.getNow("/api/persons", response -> {
// ...
// Dont' forget to release the service
reference.release();
});
}
});
}
示例4: example2_webclient
import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
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();
});
}
});
}
示例5: example2
import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
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();
});
}
});
}
示例6: example2
import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
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
RedisClient client = reference.getAs(RedisClient.class);
// ...
// when done
reference.release();
}
});
}
示例7: example2
import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
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();
}
});
}
示例8: example2
import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
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();
}
});
}
示例9: getProxy
import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
/**
* 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;
}
示例10: getServiceProxy
import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
/**
* 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;
}
示例11: getServiceProxyWithJsonFilter
import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
/**
* 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;
}
示例12: getSchemaProxy
import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
/**
* 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));
}
}
示例13: publishTestRecord
import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
@Test
public void givenServiceDiscovery_whenPublishServiceWithMetadataAndLookupForItsServiceReferencePassingConfiguration_thenShouldGetTheReferenceUponTheseConfigurations(TestContext context) throws Exception {
publishTestRecord(record, context.asyncAssertSuccess(record -> {
ServiceReference reference = vertxServiceDiscovery.lookupForAReferenceWithConfiguration(record, metadata);
assertEquals(VALUE, reference.record().getMetadata().getString(KEY));
}));
}
示例14: get
import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
@Override
public ServiceReference get(Vertx vertx, ServiceDiscovery discovery, Record record, JsonObject configuration) {
Objects.requireNonNull(vertx);
Objects.requireNonNull(record);
Objects.requireNonNull(discovery);
return new OAuth2ServiceReference(vertx, discovery, record, configuration);
}
示例15: getServiceRef
import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
private void getServiceRef(JsonObject filter, Handler<AsyncResult<ServiceReference>> handler) {
discovery.getRecord(filter, ar -> {
if (ar.succeeded() && ar.result() != null) {
ServiceReference ref = discovery.<HttpClient>getReference(ar.result());
handler.handle(Future.succeededFuture(ref));
} else {
handler.handle(Future.failedFuture(ar.cause()));
}
});
}