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

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

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

Record.setMetadata介绍

暂无

代码示例

代码示例来源: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: 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

/**
 * 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

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: io.vertx/vertx-service-discovery

/**
 * Sugar method to creates a record for this type.
 * <p>
 * The java interface is added to the metadata in the `service.interface` key.
 *
 * @param name     the name of the service.
 * @param address  the event bus address on which the service available
 * @param itf      the Java interface (name)
 * @param metadata the metadata
 * @return the created record
 */
static Record createRecord(String name, String address, String itf, JsonObject metadata) {
 Objects.requireNonNull(name);
 Objects.requireNonNull(itf);
 Objects.requireNonNull(address);
 JsonObject meta;
 if (metadata == null) {
  meta = new JsonObject();
 } else {
  meta = metadata.copy();
 }
 return new Record()
  .setType(TYPE)
  .setName(name)
  .setMetadata(meta.put("service.interface", itf))
  .setLocation(new JsonObject().put(Record.ENDPOINT, address));
}

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

/**
 * Sugar method to creates a record for this type.
 * <p>
 * The java interface is added to the metadata in the `service.interface` key.
 *
 * @param name     the name of the service.
 * @param address  the event bus address on which the service available
 * @param itf      the Java interface (name)
 * @param metadata the metadata
 * @return the created record
 */
static Record createRecord(String name, String address, String itf, JsonObject metadata) {
 Objects.requireNonNull(name);
 Objects.requireNonNull(itf);
 Objects.requireNonNull(address);
 JsonObject meta;
 if (metadata == null) {
  meta = new JsonObject();
 } else {
  meta = metadata.copy();
 }
 return new Record()
  .setType(TYPE)
  .setName(name)
  .setMetadata(meta.put("service.interface", itf))
  .setLocation(new JsonObject().put(Record.ENDPOINT, address));
}

代码示例来源: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: vert-x3/vertx-service-discovery

private Future serviceToRecord(Service service) {
  //use the checks to set the record status
  Future<CheckList> checkListFuture = Future.future();
  client.healthChecks(service.getName(), checkListFuture);
  return checkListFuture.map(cl -> cl.getList().stream().map(Check::getStatus).allMatch(CheckStatus.PASSING::equals))
   .map(st -> st ? new Record().setStatus(Status.UP) : new Record().setStatus(Status.DOWN))
   .map(record -> {
    record.setMetadata(new JsonObject());
    record.setLocation(new JsonObject());
    record.setName(service.getName());
    record.setRegistration(service.getId());
    List<String> tags = service.getTags();
    record.setType(ServiceType.UNKNOWN);
    ServiceTypes.all().forEachRemaining(type -> {
     if (service.getTags().contains(type.name())) {
      record.setType(type.name());
      tags.remove(type.name());
     }
    });
    //retrieve the metadata object
    tags.stream().filter(t -> t.startsWith("metadata:")).map(s -> s.substring("metadata:".length())).map(JsonObject::new).forEach(json -> record.getMetadata().mergeIn(json));
    //retrieve the location object
    tags.stream().filter(t -> t.startsWith("location:")).map(s -> s.substring("location:".length())).map(JsonObject::new).forEach(json -> record.getLocation().mergeIn(json));
    record.getMetadata().put("tags", new JsonArray(tags.stream().filter(t -> !t.startsWith("metadata:") && !t.startsWith("location:")).collect(Collectors.toList())));
    return record;
   });
 }
}

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

private Record createRecord(Service service) {
 String address = service.getAddress();
 int port = service.getPort();
 JsonObject metadata = service.toJson();
 if (service.getTags() != null) {
  service.getTags().forEach(tag -> metadata.put(tag, true));
 }
 Record record = new Record()
   .setName(service.getName())
   .setMetadata(metadata);
 // To determine the record type, check if we have a tag with a "type" name
 record.setType(ServiceType.UNKNOWN);
 ServiceTypes.all().forEachRemaining(type -> {
  if (metadata.getBoolean(type.name(), false)) {
   record.setType(type.name());
  }
 });
 JsonObject location = new JsonObject();
 location.put("host", address);
 location.put("port", port);
 // Manage HTTP endpoint
 if (record.getType().equals("http-endpoint")) {
  if (metadata.getBoolean("ssl", false)) {
   location.put("ssl", true);
  }
  location = new HttpLocation(location).toJson();
 }
 record.setLocation(location);
 return record;
}

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

private Record createRecord(Service service) {
 String address = service.getAddress();
 int port = service.getPort();
 JsonObject metadata = service.toJson();
 if (service.getTags() != null) {
  service.getTags().forEach(tag -> metadata.put(tag, true));
 }
 Record record = new Record()
   .setName(service.getName())
   .setMetadata(metadata);
 // To determine the record type, check if we have a tag with a "type" name
 record.setType(ServiceType.UNKNOWN);
 ServiceTypes.all().forEachRemaining(type -> {
  if (metadata.getBoolean(type.name(), false)) {
   record.setType(type.name());
  }
 });
 JsonObject location = new JsonObject();
 location.put("host", address);
 location.put("port", port);
 // Manage HTTP endpoint
 if (record.getType().equals("http-endpoint")) {
  if (metadata.getBoolean("ssl", false)) {
   location.put("ssl", true);
  }
  location = new HttpLocation(location).toJson();
 }
 record.setLocation(location);
 return record;
}

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

/**
 * Same as {@link #createRecord(String, String, int, String, JsonObject)} but let you configure whether or not the
 * service is using {@code https}.
 *
 * @param name     the service name
 * @param ssl      whether or not the service is using HTTPS
 * @param host     the host (IP or DNS name), it must be the _public_ IP / name
 * @param port     the port, it must be the _public_ port
 * @param root     the path of the service, "/" if not set
 * @param metadata additional metadata
 * @return the created record
 */
static Record createRecord(String name, boolean ssl, String host, int port, String root, JsonObject metadata) {
 Objects.requireNonNull(name);
 Objects.requireNonNull(host);
 if (root == null) {
  root = "/";
 }
 Record record = new Record().setName(name)
  .setType(TYPE)
  .setLocation(new HttpLocation()
   .setSsl(ssl).setHost(host).setPort(port).setRoot(root).toJson());
 if (metadata != null) {
  record.setMetadata(metadata);
 }
 return record;
}

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

/**
 * Same as {@link #createRecord(String, String, int, String, JsonObject)} but let you configure whether or not the
 * service is using {@code https}.
 *
 * @param name     the service name
 * @param ssl      whether or not the service is using HTTPS
 * @param host     the host (IP or DNS name), it must be the _public_ IP / name
 * @param port     the port, it must be the _public_ port
 * @param root     the path of the service, "/" if not set
 * @param metadata additional metadata
 * @return the created record
 */
static Record createRecord(String name, boolean ssl, String host, int port, String root, JsonObject metadata) {
 Objects.requireNonNull(name);
 Objects.requireNonNull(host);
 if (root == null) {
  root = "/";
 }
 Record record = new Record().setName(name)
  .setType(TYPE)
  .setLocation(new HttpLocation()
   .setSsl(ssl).setHost(host).setPort(port).setRoot(root).toJson());
 if (metadata != null) {
  record.setMetadata(metadata);
 }
 return record;
}

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

.setMetadata(new JsonObject()
 .put("key", "A")
 .put("service.interface", HelloService.class.getName()))

代码示例来源: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: io.vertx/vertx-service-discovery

@Test
public void testAnnounce() {
 List<Record> announces = new ArrayList<>();
 vertx.eventBus().consumer(ServiceDiscoveryOptions.DEFAULT_ANNOUNCE_ADDRESS,
  msg -> announces.add(new Record((JsonObject) msg.body())));
 HelloService svc = new HelloServiceImpl("stuff");
 ProxyHelper.registerService(HelloService.class, vertx, svc, "address");
 Record record = new Record()
  .setName("Hello")
  .setMetadata(new JsonObject().put("key", "A"))
  .setLocation(new JsonObject().put(Record.ENDPOINT, "address"));
 Record record2 = new Record()
  .setName("Hello-2")
  .setMetadata(new JsonObject().put("key", "B"))
  .setLocation(new JsonObject().put(Record.ENDPOINT, "address2"));
 discovery.publish(record, (r) -> {
 });
 discovery.publish(record2, (r) -> {
 });
 await().until(() -> record.getRegistration() != null);
 await().until(() -> record2.getRegistration() != null);
 await().until(() -> announces.size() == 2);
 for (Record rec : announces) {
  assertThat(rec.getStatus()).isEqualTo(Status.UP);
 }
 discovery.unpublish(record2.getRegistration(), v -> {
 });
 await().until(() -> announces.size() == 3);
 assertThat(announces.get(2).getStatus()).isEqualTo(Status.DOWN);
}

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

@Test
public void testAnnounce() {
 List<Record> announces = new ArrayList<>();
 vertx.eventBus().consumer(ServiceDiscoveryOptions.DEFAULT_ANNOUNCE_ADDRESS,
  msg -> announces.add(new Record((JsonObject) msg.body())));
 HelloService svc = new HelloServiceImpl("stuff");
 ProxyHelper.registerService(HelloService.class, vertx, svc, "address");
 Record record = new Record()
  .setName("Hello")
  .setMetadata(new JsonObject().put("key", "A"))
  .setLocation(new JsonObject().put(Record.ENDPOINT, "address"));
 Record record2 = new Record()
  .setName("Hello-2")
  .setMetadata(new JsonObject().put("key", "B"))
  .setLocation(new JsonObject().put(Record.ENDPOINT, "address2"));
 discovery.publish(record, (r) -> {
 });
 discovery.publish(record2, (r) -> {
 });
 await().until(() -> record.getRegistration() != null);
 await().until(() -> record2.getRegistration() != null);
 await().until(() -> announces.size() == 2);
 for (Record rec : announces) {
  assertThat(rec.getStatus()).isEqualTo(Status.UP);
 }
 discovery.unpublish(record2.getRegistration(), v -> {
 });
 await().until(() -> announces.size() == 3);
 assertThat(announces.get(2).getStatus()).isEqualTo(Status.DOWN);
}

相关文章