本文整理汇总了Java中io.vertx.servicediscovery.ServiceDiscovery类的典型用法代码示例。如果您正苦于以下问题:Java ServiceDiscovery类的具体用法?Java ServiceDiscovery怎么用?Java ServiceDiscovery使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServiceDiscovery类属于io.vertx.servicediscovery包,在下文中一共展示了ServiceDiscovery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import io.vertx.servicediscovery.ServiceDiscovery; //导入依赖的package包/类
@Override
public void start() throws Exception {
Router router = Router.router(vertx);
router.get("/shopping").handler(this::getList);
router.route().handler(BodyHandler.create());
router.post("/shopping").handler(this::addToList);
router.delete("/shopping/:name").handler(this::deleteFromList);
ServiceDiscovery.create(vertx, discovery -> {
RedisDataSource.getRedisClient(discovery, rec -> rec.getName().equals("redis"), ar -> {
redis = ar.result();
vertx.createHttpServer()
.requestHandler(router::accept)
.listen(8080);
});
});
}
示例2: getServiceDiscovery
import io.vertx.servicediscovery.ServiceDiscovery; //导入依赖的package包/类
static ServiceDiscovery getServiceDiscovery(io.vertx.core.Vertx vertx) {
// Discovery settings
ServiceDiscoveryOptions serviceDiscoveryOptions = new ServiceDiscoveryOptions();
// Redis settings with the standard Redis Backend
Integer redisPort = Integer.parseInt(Optional.ofNullable(System.getenv("REDIS_PORT")).orElse("6379"));
String redisHost = Optional.ofNullable(System.getenv("REDIS_HOST")).orElse("127.0.0.1");
String redisAuth = Optional.ofNullable(System.getenv("REDIS_PASSWORD")).orElse(null);
String redisRecordsKey = Optional.ofNullable(System.getenv("REDIS_RECORDS_KEY")).orElse("vert.x.ms"); // the redis hash
return ServiceDiscovery.create(
vertx,
serviceDiscoveryOptions.setBackendConfiguration(
new JsonObject()
.put("host", redisHost)
.put("port", redisPort)
.put("auth", redisAuth)
.put("key", redisRecordsKey)
));
}
示例3: deleteService
import io.vertx.servicediscovery.ServiceDiscovery; //导入依赖的package包/类
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);
successLog(record);
// Sync deleted
REGISTRITIONS.remove(id);
ID_MAP.remove(id);
} else {
LOGGER.info(Info.REG_FAILURE, result.cause().getMessage(), "Delete");
}
});
});
}
示例4: addService
import io.vertx.servicediscovery.ServiceDiscovery; //导入依赖的package包/类
private void addService(final ServiceDiscovery discovery,
final Set<String> ids,
final ConcurrentMap<String, Record> services) {
// Add service into current zero system.
Observable.fromIterable(ids)
.map(services::get)
.subscribe(item -> discovery.publish(item, result -> {
if (result.succeeded()) {
final Record record = result.result();
// Add successfully
successFinished(record);
} else {
LOGGER.info(Info.REG_FAILURE, result.cause().getMessage(), "Add");
}
}));
}
示例5: start
import io.vertx.servicediscovery.ServiceDiscovery; //导入依赖的package包/类
@Override
public void start() {
Router router = Router.router(vertx);
router.get("/").handler(rc -> rc.response().end("hello "));
router.get("/shopping").handler(this::getList);
router.post().handler(BodyHandler.create());
router.post("/shopping").handler(this::addToList);
router.delete("/shopping/:name").handler(this::removeFromList);
ServiceDiscovery.create(vertx, discovery -> {
RedisDataSource.getRedisClient(discovery, svc -> svc.getName().equals("redis"), ar -> {
if (ar.failed()) {
System.out.println("D'oh");
} else {
redis = ar.result();
vertx.createHttpServer()
.requestHandler(router::accept)
.listen(8080);
}
});
});
}
开发者ID:cescoffier,项目名称:vertx-kubernetes-live-coding-devoxx-ma,代码行数:26,代码来源:ShoppingBackendVerticle.java
示例6: start
import io.vertx.servicediscovery.ServiceDiscovery; //导入依赖的package包/类
@Override
public void start() {
Router router = Router.router(vertx);
router.get("/").handler(rc -> rc.response().end("Hello Austin"));
router.get("/shopping").handler(this::getList);
router.post().handler(BodyHandler.create());
router.post("/shopping").handler(this::addToList);
router.delete("/shopping/:name").handler(this::deleteFromList);
ServiceDiscovery.create(vertx, discovery -> {
RedisDataSource.getRedisClient(discovery, svc -> svc.getName().equals("redis"), ar -> {
if (ar.failed()) {
System.out.println("D'oh");
} else {
redis = ar.result();
vertx.createHttpServer()
.requestHandler(router::accept)
.listen(8080);
}
});
});
}
示例7: ServiceFinderImpl
import io.vertx.servicediscovery.ServiceDiscovery; //导入依赖的package包/类
ServiceFinderImpl(Vertx vertx, ServiceDiscovery discovery) {
this.discovery = discovery;
//启动时加载所有服务
reload(ar -> {
if (ar.succeeded()) {
Log.create(LOGGER)
.setEvent("service.load.succeed");
} else {
Log.create(LOGGER)
.setEvent("service.load.failure")
.setThrowable(ar.cause());
}
});
//每次收到某个服务的变动,就根据服务名重新加载所有服务
String announce = discovery.options().getAnnounceAddress();
vertx.eventBus().<JsonObject>consumer(announce, msg -> {
Record record = new Record(msg.body());
String name = record.getName();
discovery.getRecords(new JsonObject().put("name", name), ar -> {
records.removeIf(r -> r.getName().endsWith(name));
records.addAll(ar.result());
});
});
}
示例8: setUp
import io.vertx.servicediscovery.ServiceDiscovery; //导入依赖的package包/类
@Before
public void setUp(TestContext tc) {
Async async = tc.async();
vertx = Vertx.vertx();
Record record = MessageSource.createRecord("portfolio-events", "portfolio", JsonObject
.class);
ServiceDiscovery.create(vertx, new ServiceDiscoveryOptions()
.setBackendConfiguration(new JsonObject().put("backend-name", DefaultServiceDiscoveryBackend.class.getName())))
.publish(record,
r -> {
if (r.failed()) {
r.cause().printStackTrace();
tc.fail(r.cause());
}
vertx.deployVerticle(AuditVerticle.class.getName(), new DeploymentOptions().setConfig(CONFIGURATION), tc.asyncAssertSuccess(s -> async.complete()));
});
}
示例9: setUp
import io.vertx.servicediscovery.ServiceDiscovery; //导入依赖的package包/类
@Before
public void setUp() {
init();
client = DockerClientBuilder.getInstance().build();
List<Container> running = client.listContainersCmd().withStatusFilter("running").exec();
if (running != null) {
running.forEach(container -> client.stopContainerCmd(container.getId()).exec());
}
vertx = Vertx.vertx();
discovery = ServiceDiscovery.create(vertx);
bridge = new DockerServiceImporter();
discovery.registerServiceImporter(bridge,
new JsonObject().put("scan-period", -1));
await().until(() -> bridge.started);
}
示例10: testInitialRetrieval
import io.vertx.servicediscovery.ServiceDiscovery; //导入依赖的package包/类
@Test
public void testInitialRetrieval(TestContext tc) {
Async async = tc.async();
ServiceDiscovery discovery = ServiceDiscovery.create(vertx, new ServiceDiscoveryOptions().setAutoRegistrationOfImporters(false));
discovery.registerServiceImporter(new KubernetesServiceImporter(), config().copy().put("namespace", "default"),
ar -> {
if (ar.failed()) {
tc.fail(ar.cause());
} else {
discovery.getRecords(s -> true, res -> {
if (res.failed()) {
tc.fail(res.cause());
} else {
tc.assertEquals(2, res.result().size());
async.complete();
}
});
}
});
}
示例11: getRecordsBlocking
import io.vertx.servicediscovery.ServiceDiscovery; //导入依赖的package包/类
private List<Record> getRecordsBlocking(ServiceDiscovery discovery) {
CountDownLatch latch = new CountDownLatch(1);
List<Record> records = new ArrayList<>();
discovery.getRecords(s -> true, ar -> {
records.addAll(ar.result());
latch.countDown();
});
try {
latch.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return records;
}
示例12: executeQuery
import io.vertx.servicediscovery.ServiceDiscovery; //导入依赖的package包/类
/**
* Executes the parametrized GraphQL query and its variables against the specified schema definition
* (aka the graphql service name) that is published to the service discovery with the specified name.
* <p>
* On success a {@link QueryResult} is returned. Note that at this point the GraphQL query may still have failed,
* so be sure to check the {@link QueryResult#getErrors()} property afterwards.
* <p>
* The top-level keys in the `variables` json represent the variable names that are used in the query string, and
* are passed with their corresponding values to the query executor.
*
* @param discoveryName the name of the service discovery
* @param schemaName the name of the schema definition to query
* @param query the GraphQL query
* @param variables the variables to pass to the query executor
* @param resultHandler the result handler
*/
default void executeQuery(String discoveryName, String schemaName, String query,
JsonObject variables, Handler<AsyncResult<QueryResult>> resultHandler) {
Objects.requireNonNull(schemaName, "Schema definition name cannot be null");
Objects.requireNonNull(query, "GraphQL query cannot be null");
Objects.requireNonNull(resultHandler, "Query result handler cannot be null");
if (!managedDiscoveries().contains(discoveryName)) {
resultHandler.handle(Future.failedFuture("Service discovery with name '" + discoveryName +
"' is not managed by this schema consumer"));
return;
}
ServiceDiscovery discovery = discoveryRegistrar().getDiscovery(discoveryName);
discovery.getRecord(record -> schemaName.equals(record.getName()), rh -> {
if (rh.succeeded() && rh.result() != null) {
GraphQLClient.executeQuery(discovery, rh.result(), query, variables, resultHandler);
} else {
resultHandler.handle(Future.failedFuture(
"Failed to find published schema '" + schemaName + "' in repository: " + discoveryName));
}
});
}
示例13: example1
import io.vertx.servicediscovery.ServiceDiscovery; //导入依赖的package包/类
public void example1(ServiceDiscovery discovery) {
Record record1 = HttpEndpoint.createRecord(
"some-http-service", // The service name
"localhost", // The host
8433, // the port
"/api" // the root of the service
);
discovery.publish(record1, ar -> {
// ...
});
Record record2 = HttpEndpoint.createRecord(
"some-other-name", // the service name
true, // whether or not the service requires HTTPs
"localhost", // The host
8433, // the port
"/api", // the root of the service
new JsonObject().put("some-metadata", "some value")
);
}
示例14: example2
import io.vertx.servicediscovery.ServiceDiscovery; //导入依赖的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();
});
}
});
}
示例15: example3
import io.vertx.servicediscovery.ServiceDiscovery; //导入依赖的package包/类
public void example3(ServiceDiscovery discovery) {
HttpEndpoint.getClient(discovery, new JsonObject().put("name", "some-http-service"), ar -> {
if (ar.succeeded()) {
HttpClient client = ar.result();
// You need to path the complete path
client.getNow("/api/persons", response -> {
// ...
// Dont' forget to release the service
ServiceDiscovery.releaseServiceObject(discovery, client);
});
}
});
}