io.vertx.servicediscovery.Record.setLocation()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(13.0k)|赞(0)|评价(0)|浏览(68)

本文整理了Java中io.vertx.servicediscovery.Record.setLocation方法的一些代码示例,展示了Record.setLocation的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Record.setLocation方法的具体详情如下:
包路径:io.vertx.servicediscovery.Record
类名称:Record
方法名:setLocation

Record.setLocation介绍

[英]Sets the json object describing the location of the service. By convention, this json object should contain the #ENDPOINT entry.
[中]设置描述服务位置的json对象。按照惯例,这个json对象应该包含#端点条目。

代码示例

代码示例来源:origin: vert-x3/vertx-examples

.setLocation(new JsonObject().put("endpoint", "the-service-address"))
.setName("my-service")
.setMetadata(new JsonObject().put("some-label", "some-value"));

代码示例来源:origin: io.vertx/vertx-service-discovery

static Record createRecord(String name, JsonObject location, JsonObject metadata) {
 Objects.requireNonNull(name);
 Objects.requireNonNull(location);
 Record record = new Record().setName(name)
   .setType(TYPE)
   .setLocation(location);
 if (metadata != null) {
  record.setMetadata(metadata);
 }
 return record;
}

代码示例来源:origin: vert-x3/vertx-service-discovery

static Record createRecord(String name, JsonObject location, JsonObject metadata) {
 Objects.requireNonNull(name);
 Objects.requireNonNull(location);
 Record record = new Record().setName(name)
   .setType(TYPE)
   .setLocation(location);
 if (metadata != null) {
  record.setMetadata(metadata);
 }
 return record;
}

代码示例来源:origin: vert-x3/vertx-service-discovery

private Record manageUnknownService(Record record, ContainerPort port) {
 if (port.getPublicPort() == null || port.getPublicPort() == 0) {
  return null;
 }
 JsonObject location = new JsonObject();
 location.put("port", port.getPublicPort());
 location.put("internal-port", port.getPrivatePort());
 location.put("type", port.getType());
 location.put("ip", host);
 return record.setLocation(location).setType(ServiceType.UNKNOWN);
}

代码示例来源:origin: vert-x3/vertx-service-discovery

/**
 * Create a record representing a data producer.
 *
 * @param name     the name of the service
 * @param address  the address on which the data is sent
 * @param type     the type of payload (fully qualified name of the class)
 * @param metadata additional metadata
 * @return the created record
 */
static Record createRecord(String name, String address, String type, JsonObject metadata) {
 Objects.requireNonNull(name);
 Objects.requireNonNull(address);
 Record record = new Record().setName(name)
   .setType(TYPE)
   .setLocation(new JsonObject().put(Record.ENDPOINT, address));
 if (metadata != null) {
  record.setMetadata(metadata);
 }
 if (type != null) {
  record.setMetadata(new JsonObject().put("message.type", type));
 }
 return record;
}

代码示例来源:origin: io.vertx/vertx-service-discovery

/**
 * Convenient method to create a record for a Redis data source.
 *
 * @param name     the service name
 * @param location the location of the service (e.g. url, port...)
 * @param metadata additional metadata
 * @return the created record
 */
static Record createRecord(String name, JsonObject location, JsonObject metadata) {
 Objects.requireNonNull(name);
 Objects.requireNonNull(location);
 Record record = new Record().setName(name)
  .setType(TYPE)
  .setLocation(location);
 if (metadata != null) {
  record.setMetadata(metadata);
 }
 return record;
}

代码示例来源:origin: vert-x3/vertx-service-discovery

/**
 * Convenient method to create a record for a Redis data source.
 *
 * @param name     the service name
 * @param location the location of the service (e.g. url, port...)
 * @param metadata additional metadata
 * @return the created record
 */
static Record createRecord(String name, JsonObject location, JsonObject metadata) {
 Objects.requireNonNull(name);
 Objects.requireNonNull(location);
 Record record = new Record().setName(name)
  .setType(TYPE)
  .setLocation(location);
 if (metadata != null) {
  record.setMetadata(metadata);
 }
 return record;
}

代码示例来源:origin: io.vertx/vertx-service-discovery

/**
 * Convenient method to create a record for a Mongo data source.
 *
 * @param name     the service name
 * @param location the location of the service (e.g. url, port...)
 * @param metadata additional metadata
 * @return the created record
 */
static Record createRecord(String name, JsonObject location, JsonObject metadata) {
 Objects.requireNonNull(name);
 Objects.requireNonNull(location);
 Record record = new Record().setName(name)
  .setType(TYPE)
  .setLocation(location);
 if (metadata != null) {
  record.setMetadata(metadata);
 }
 return record;
}

代码示例来源:origin: vert-x3/vertx-service-discovery

/**
 * Convenient method to create a record for a Mongo data source.
 *
 * @param name     the service name
 * @param location the location of the service (e.g. url, port...)
 * @param metadata additional metadata
 * @return the created record
 */
static Record createRecord(String name, JsonObject location, JsonObject metadata) {
 Objects.requireNonNull(name);
 Objects.requireNonNull(location);
 Record record = new Record().setName(name)
  .setType(TYPE)
  .setLocation(location);
 if (metadata != null) {
  record.setMetadata(metadata);
 }
 return record;
}

代码示例来源:origin: engagingspaces/vertx-graphql-service-discovery

@Before
public void setUp() {
  vertx = Vertx.vertx();
  discovery = ServiceDiscovery.create(vertx, new ServiceDiscoveryOptions().setName("test-discovery"));
  config = new JsonObject().put("deliveryOptions",
      new JsonObject().put("timeout", 1000).put("codecName", "theCodecName"));
  record = new Record().setLocation(new JsonObject().put(Record.ENDPOINT, "theEndpoint"));
  graphQLService = new io.engagingspaces.graphql.servicediscovery.service.impl.GraphQLServiceImpl();
}

代码示例来源:origin: vert-x3/vertx-service-discovery

private static void manageHttpService(Record record, JsonObject service) {
 JsonObject spec = service.getJsonObject("spec");
 JsonArray ports = spec.getJsonArray("ports");
 if (ports != null && !ports.isEmpty()) {
  if (ports.size() > 1) {
   LOGGER.warn("More than one port has been found for " + record.getName() + " - taking the first" +
    " one to extract the HTTP endpoint location");
  }
  JsonObject port = ports.getJsonObject(0);
  Integer p = port.getInteger("port");
  record.setType(HttpEndpoint.TYPE);
  HttpLocation location = new HttpLocation(port.copy());
  if (isExternalService(service)) {
   location.setHost(spec.getString("externalName"));
  } else {
   location.setHost(spec.getString("clusterIP"));
  }
  if (isTrue(record.getMetadata().getString("ssl")) || p != null && p == 443) {
   location.setSsl(true);
  }
  record.setLocation(location.toJson());
 } else {
  throw new IllegalStateException("Cannot extract the HTTP URL from the service " + record + " - no port");
 }
}

代码示例来源:origin: io.vertx/vertx-service-discovery

@Test
public void testFailedPublication() {
 HelloService svc = new HelloServiceImpl("stuff");
 ProxyHelper.registerService(HelloService.class, vertx, svc, "address");
 Record record = new Record()
  .setName("Hello")
  .setRegistration("this-is-not-allowed")
  .setLocation(new JsonObject().put(Record.ENDPOINT, "address"));
 Restafari.Response response = given().request().body(record.toJson().toString()).post("/discovery");
 assertThat(response.getStatusCode()).isEqualTo(500);
}

代码示例来源:origin: engagingspaces/vertx-graphql-service-discovery

@Before
public void setUp() {
  vertx = Vertx.vertx();
  options = new ServiceDiscoveryOptions().setName("theDiscovery")
      .setAnnounceAddress("theAnnounceAddress").setUsageAddress("theUsageAddress");
  discovery = ServiceDiscovery.create(vertx, options);
  record = new Record()
      .setName("theRecord")
      .setType(Queryable.SERVICE_TYPE)
      .setMetadata(new JsonObject().put("publisherId", "thePublisherId"))
      .setLocation(new JsonObject().put(Record.ENDPOINT, Queryable.ADDRESS_PREFIX + ".DroidQueries"))
      .setStatus(Status.UP);
  definition = SchemaDefinition.createInstance(droidsSchema,
      SchemaMetadata.create(new JsonObject().put("publisherId", "thePublisherId")));
  consumer = ProxyHelper.registerService(Queryable.class,
      vertx, definition, Queryable.ADDRESS_PREFIX + ".DroidQueries");
}

代码示例来源:origin: vert-x3/vertx-service-discovery

@Test
public void testFailedPublication() {
 HelloService svc = new HelloServiceImpl("stuff");
 ProxyHelper.registerService(HelloService.class, vertx, svc, "address");
 Record record = new Record()
  .setName("Hello")
  .setRegistration("this-is-not-allowed")
  .setLocation(new JsonObject().put(Record.ENDPOINT, "address"));
 Restafari.Response response = given().request().body(record.toJson().toString()).post("/discovery");
 assertThat(response.getStatusCode()).isEqualTo(500);
}

代码示例来源:origin: io.vertx/vertx-service-discovery

@Test
public void testThatWeGetThePublishedServices() {
 HelloService svc = new HelloServiceImpl("stuff");
 ProxyHelper.registerService(HelloService.class, vertx, svc, "address");
 Record record = new Record()
  .setName("Hello")
  .setLocation(new JsonObject().put(Record.ENDPOINT, "address"));
 discovery.publish(record, (r) -> {
 });
 await().until(() -> record.getRegistration() != null);
 Restafari.Response response = get("/discovery");
 JsonArray services = new JsonArray(response.asString());
 assertThat(services.size()).isEqualTo(1);
 Record rec = new Record(services.getJsonObject(0));
 assertThat(rec.getStatus()).isEqualTo(Status.UP);
 assertThat(rec.getRegistration()).isNotNull();
 assertThat(rec.getName()).isEqualTo("Hello");
 AtomicBoolean done = new AtomicBoolean();
 discovery.unpublish(record.getRegistration(), ar -> done.set(true));
 await().untilAtomic(done, is(true));
 response = get("/discovery");
 services = new JsonArray(response.asString());
 assertThat(services.size()).isEqualTo(0);
}

代码示例来源:origin: vert-x3/vertx-service-discovery

@Test
public void testRetrievingMissingRecord() {
 HelloService svc = new HelloServiceImpl("stuff");
 ProxyHelper.registerService(HelloService.class, vertx, svc, "address");
 Record record = new Record()
  .setName("Hello")
  .setLocation(new JsonObject().put(Record.ENDPOINT, "address"));
 discovery.publish(record, (r) -> {
 });
 await().until(() -> record.getRegistration() != null);
 Record retrieved = retrieve(record.getRegistration());
 assertThat(retrieved.getStatus()).isEqualTo(Status.UP);
 // Unregister it
 Restafari.Response response2 = delete("/discovery/" + record.getRegistration());
 assertThat(response2.getStatusCode()).isEqualTo(204);
 Restafari.Response response = get("/discovery/" + record.getRegistration());
 assertThat(response.getStatusCode()).isEqualTo(404);
}

代码示例来源:origin: io.vertx/vertx-service-discovery

@Test
public void testRetrievingMissingRecord() {
 HelloService svc = new HelloServiceImpl("stuff");
 ProxyHelper.registerService(HelloService.class, vertx, svc, "address");
 Record record = new Record()
  .setName("Hello")
  .setLocation(new JsonObject().put(Record.ENDPOINT, "address"));
 discovery.publish(record, (r) -> {
 });
 await().until(() -> record.getRegistration() != null);
 Record retrieved = retrieve(record.getRegistration());
 assertThat(retrieved.getStatus()).isEqualTo(Status.UP);
 // Unregister it
 Restafari.Response response2 = delete("/discovery/" + record.getRegistration());
 assertThat(response2.getStatusCode()).isEqualTo(204);
 Restafari.Response response = get("/discovery/" + record.getRegistration());
 assertThat(response.getStatusCode()).isEqualTo(404);
}

代码示例来源:origin: vert-x3/vertx-service-discovery

private static Record manageHttpService(Record record, ContainerPort port, Map<String, String> labels) {
 if (port.getPublicPort() == null || port.getPublicPort() == 0) {
  return null;
 }
 record.setType(HttpEndpoint.TYPE);
 HttpLocation location = new HttpLocation()
   .setHost(port.getIp())
   .setPort(port.getPublicPort());
 if (isTrue(labels, "ssl")  || port.getPrivatePort() == 443) {
  location.setSsl(true);
 }
 return record.setLocation(location.toJson());
}

代码示例来源:origin: io.vertx/vertx-service-discovery

@Test
public void testUpdateWithUUIDMismatch() throws UnsupportedEncodingException {
 HelloService svc = new HelloServiceImpl("stuff");
 ProxyHelper.registerService(HelloService.class, vertx, svc, "address");
 Record record = new Record()
  .setName("Hello")
  .setLocation(new JsonObject().put(Record.ENDPOINT, "address"));
 discovery.publish(record, (r) -> {
 });
 await().until(() -> record.getRegistration() != null);
 Record retrieved = retrieve(record.getRegistration());
 assertThat(retrieved.getStatus()).isEqualTo(Status.UP);
 retrieved.setStatus(Status.OUT_OF_SERVICE).setRegistration("not-the-right-one").getMetadata().put("foo", "bar");
 Restafari.Response response = given().body(retrieved.toJson().toString())
  .put("/discovery/" + record.getRegistration());
 assertThat(response.getStatusCode()).isEqualTo(400);
}

代码示例来源:origin: vert-x3/vertx-service-discovery

@Test
public void testUpdateWithUUIDMismatch() throws UnsupportedEncodingException {
 HelloService svc = new HelloServiceImpl("stuff");
 ProxyHelper.registerService(HelloService.class, vertx, svc, "address");
 Record record = new Record()
  .setName("Hello")
  .setLocation(new JsonObject().put(Record.ENDPOINT, "address"));
 discovery.publish(record, (r) -> {
 });
 await().until(() -> record.getRegistration() != null);
 Record retrieved = retrieve(record.getRegistration());
 assertThat(retrieved.getStatus()).isEqualTo(Status.UP);
 retrieved.setStatus(Status.OUT_OF_SERVICE).setRegistration("not-the-right-one").getMetadata().put("foo", "bar");
 Restafari.Response response = given().body(retrieved.toJson().toString())
  .put("/discovery/" + record.getRegistration());
 assertThat(response.getStatusCode()).isEqualTo(400);
}

相关文章