当前位置: 首页>>代码示例>>Java>>正文


Java ServiceDiscovery类代码示例

本文整理汇总了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);
        });
    });
}
 
开发者ID:cescoffier,项目名称:vertx-chtijug-2017,代码行数:19,代码来源:MyShoppingVerticle.java

示例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)
    ));
}
 
开发者ID:the-big-bang-theory,项目名称:penny,代码行数:21,代码来源:Parameters.java

示例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");
                    }
                });
            });
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:21,代码来源:ZeroApiWorker.java

示例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");
                }
            }));
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:17,代码来源:ZeroApiWorker.java

示例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);
            }
        });
    });

}
 
开发者ID:cescoffier,项目名称:vertx-reactive-summit-2017,代码行数:24,代码来源:ShoppingBackendVerticle.java

示例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());
    });
  });
}
 
开发者ID:edgar615,项目名称:direwolves,代码行数:25,代码来源:ServiceFinderImpl.java

示例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()));
          });
}
 
开发者ID:cescoffier,项目名称:vertx-microservices-workshop,代码行数:18,代码来源:AuditVerticleTest.java

示例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);
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:19,代码来源:DockerBridgeTest.java

示例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();
          }
        });
      }
    });
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:21,代码来源:KubernetesServerTest.java

示例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;
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:17,代码来源:KubernetesServerTest.java

示例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));
        }
    });
}
 
开发者ID:engagingspaces,项目名称:vertx-graphql-service-discovery,代码行数:38,代码来源:SchemaConsumer.java

示例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")
  );

}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:23,代码来源:HTTPEndpointExamples.java

示例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();

      });
    }
  });
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:22,代码来源:HTTPEndpointExamples.java

示例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);

      });
    }
  });
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:18,代码来源:HTTPEndpointExamples.java


注:本文中的io.vertx.servicediscovery.ServiceDiscovery类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。