Java Code Examples for io.vertx.servicediscovery.ServiceDiscovery#publish()

The following examples show how to use io.vertx.servicediscovery.ServiceDiscovery#publish() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HTTPEndpointExamples.java    From vertx-service-discovery with Apache License 2.0 6 votes vote down vote up
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")
  );

}
 
Example 2
Source File: MessageSourceExamples.java    From vertx-service-discovery with Apache License 2.0 6 votes vote down vote up
public void example1(ServiceDiscovery discovery) {
  Record record = MessageSource.createRecord(
      "some-message-source-service", // The service name
      "some-address" // The event bus address
  );

  discovery.publish(record, ar -> {
    // ...
  });

  record = MessageSource.createRecord(
      "some-other-message-source-service", // The service name
      "some-address", // The event bus address
      "examples.MyData" // The payload type
  );
}
 
Example 3
Source File: RedisDataSourceExamples.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
public void example1(ServiceDiscovery discovery) {
  Record record = RedisDataSource.createRecord(
    "some-redis-data-source-service", // The service name
    new JsonObject().put("url", "localhost"), // The location
    new JsonObject().put("some-metadata", "some-value") // Some metadata
  );

  discovery.publish(record, ar -> {
    // ...
  });
}
 
Example 4
Source File: EventBusServiceJavaExamples.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
public void example1(ServiceDiscovery discovery) {
  Record record = EventBusService.createRecord(
      "some-eventbus-service", // The service name
      "address", // the service address,
      MyService.class // the service interface
  );

  discovery.publish(record, ar -> {
    // ...
  });

}
 
Example 5
Source File: JDBCDataSourceExamples.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
public void example1(ServiceDiscovery discovery) {
  Record record = JDBCDataSource.createRecord(
      "some-data-source-service", // The service name
      new JsonObject().put("url", "some jdbc url"), // The location
      new JsonObject().put("some-metadata", "some-value") // Some metadata
  );

  discovery.publish(record, ar -> {
    // ...
  });
}
 
Example 6
Source File: MongoDataSourceExamples.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
public void example1(ServiceDiscovery discovery) {
  Record record = MongoDataSource.createRecord(
    "some-data-source-service", // The service name
    new JsonObject().put("connection_string", "some mongo connection"), // The location
    new JsonObject().put("some-metadata", "some-value") // Some metadata
  );

  discovery.publish(record, ar -> {
    // ...
  });
}
 
Example 7
Source File: EventBusServiceExamples.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
public void example1(ServiceDiscovery discovery) {
  Record record = EventBusService.createRecord(
      "some-eventbus-service", // The service name
      "address", // the service address,
      "examples.MyService", // the service interface as string
      new JsonObject()
          .put("some-metadata", "some value")
  );

  discovery.publish(record, ar -> {
    // ...
  });
}
 
Example 8
Source File: GraphQLService.java    From vertx-graphql-service-discovery with Apache License 2.0 5 votes vote down vote up
/**
 * Publish a GraphQL schema for querying.
 * <p>
 * On success a {@link SchemaRegistration} is returned. It contains the message consumer of the
 * {@link Queryable} service proxy that supplies the published {@link SchemaDefinition}, the published service
 * discovery record, and the {@link ServiceDiscovery} it was published to.
 * <p>
 * Note that unless invoked from a {@link SchemaPublisher} a
 * client needs to keep hold of the returned {@link Record} as long as it is published.
 *
 * @param vertx         the vert.x instance
 * @param discovery     the service discovery instance
 * @param definition    the service proxy instance exposing the graphql schema
 * @param resultHandler the result handler that returns the registration
 */
static void publish(Vertx vertx, ServiceDiscovery discovery, SchemaDefinition definition,
                    Handler<AsyncResult<SchemaRegistration>> resultHandler) {

    Objects.requireNonNull(vertx, "Vertx cannot be null");
    Objects.requireNonNull(discovery, "Service discovery cannot be null");
    Objects.requireNonNull(definition, "GraphQL queryable cannot be null");
    Objects.requireNonNull(resultHandler, "Publication result handler cannot be null");

    // TODO Caching proxy ok?

    final MessageConsumer<JsonObject> serviceConsumer;
    if (definition.metadata().get("publisherId") == null) {
        serviceConsumer = ProxyHelper.registerService(
                Queryable.class, vertx, definition, definition.serviceAddress());
    } else {
        // Publisher handles service instantiation, manages consumer.
        serviceConsumer = null;
    }

    Record record = new Record()
            .setType(SERVICE_TYPE)
            .setName(definition.schemaName())
            .setMetadata(definition.metadata().toJson())
            .setLocation(new JsonObject().put(Record.ENDPOINT, definition.serviceAddress()));

    discovery.publish(record, rh -> {
        if (rh.succeeded()) {
            resultHandler.handle(Future.succeededFuture(
                    SchemaRegistration.create(discovery, null, rh.result(), definition, serviceConsumer)));
        } else {
            resultHandler.handle(Future.failedFuture(rh.cause()));
        }
    });
}