Class ServiceDiscovery


  • public class ServiceDiscovery
    extends Object
    Service Discovery main entry point.

    The service discovery is an infrastructure that let you publish and find `services`. A `service` is a discoverable functionality. It can be qualified by its type, metadata, and location. So a `service` can be a database, a service proxy, a HTTP endpoint. It does not have to be a vert.x entity, but can be anything. Each service is described by a Record.

    The service discovery implements the interactions defined in the service-oriented computing. And to some extend, also provides the dynamic service-oriented computing interaction. So, application can react to arrival and departure of services.

    A service provider can:

    * publish a service record * un-publish a published record * update the status of a published service (down, out of service...)

    A service consumer can:

    * lookup for services * bind to a selected service (it gets a ServiceReference) and use it * release the service once the consumer is done with it * listen for arrival, departure and modification of services.

    Consumer would 1) lookup for service record matching their need, 2) retrieve the ServiceReference that give access to the service, 3) get a service object to access the service, 4) release the service object once done.

    A state above, the central piece of information shared by the providers and consumers are Record.

    Providers and consumers must create their own ServiceDiscovery instance. These instances are collaborating in background (distributed structure) to keep the set of services in sync.

    NOTE: This class has been automatically generated from the original non Mutiny-ified interface using Vert.x codegen.

    • Constructor Detail

      • ServiceDiscovery

        public ServiceDiscovery​(io.vertx.servicediscovery.ServiceDiscovery delegate)
      • ServiceDiscovery

        public ServiceDiscovery​(Object delegate)
    • Method Detail

      • getDelegate

        public io.vertx.servicediscovery.ServiceDiscovery getDelegate()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • create

        public static ServiceDiscovery create​(Vertx vertx,
                                              io.vertx.servicediscovery.ServiceDiscoveryOptions options)
        Parameters:
        vertx - the vert.x instance
        options - the discovery options
        Returns:
        the created service discovery instance.
      • create

        public static ServiceDiscovery create​(Vertx vertx)
        Parameters:
        vertx - the vert.x instance
        Returns:
        the created instance
      • getReference

        public ServiceReference getReference​(io.vertx.servicediscovery.Record record)
        Parameters:
        record - the chosen record
        Returns:
        the service reference, that allows retrieving the service object. Once called the service reference is cached, and need to be released.
      • getReferenceWithConfiguration

        public ServiceReference getReferenceWithConfiguration​(io.vertx.servicediscovery.Record record,
                                                              io.vertx.core.json.JsonObject configuration)
        Parameters:
        record - the chosen record
        configuration - the configuration
        Returns:
        the service reference, that allows retrieving the service object. Once called the service reference is cached, and need to be released.
      • release

        public boolean release​(ServiceReference reference)
        Parameters:
        reference - the reference to release, must not be null
        Returns:
        whether or not the reference has been released.
      • registerServiceImporter

        public io.smallrye.mutiny.Uni<Void> registerServiceImporter​(ServiceImporter importer,
                                                                    io.vertx.core.json.JsonObject configuration)
        Registers a discovery service importer. Importers let you integrate other discovery technologies in this service discovery.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        importer - the service importer
        configuration - the optional configuration
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • registerServiceImporterAndAwait

        public Void registerServiceImporterAndAwait​(ServiceImporter importer,
                                                    io.vertx.core.json.JsonObject configuration)
        Blocking variant of registerServiceImporter(io.vertx.mutiny.servicediscovery.spi.ServiceImporter,JsonObject).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        importer - the service importer
        configuration - the optional configuration
        Returns:
        the Void instance produced by the operation.
      • registerServiceExporter

        public io.smallrye.mutiny.Uni<Void> registerServiceExporter​(ServiceExporter exporter,
                                                                    io.vertx.core.json.JsonObject configuration)
        Registers a discovery bridge. Exporters let you integrate other discovery technologies in this service discovery.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        exporter - the service exporter
        configuration - the optional configuration
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • registerServiceExporterAndAwait

        public Void registerServiceExporterAndAwait​(ServiceExporter exporter,
                                                    io.vertx.core.json.JsonObject configuration)
        Blocking variant of registerServiceExporter(io.vertx.mutiny.servicediscovery.spi.ServiceExporter,JsonObject).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        exporter - the service exporter
        configuration - the optional configuration
        Returns:
        the Void instance produced by the operation.
      • close

        public void close()
      • publish

        public io.smallrye.mutiny.Uni<io.vertx.servicediscovery.Record> publish​(io.vertx.servicediscovery.Record record)
        Publishes a record.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        record - the record
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • publishAndAwait

        public io.vertx.servicediscovery.Record publishAndAwait​(io.vertx.servicediscovery.Record record)
        Blocking variant of publish(Record).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        record - the record
        Returns:
        the Record instance produced by the operation.
      • publishAndForget

        public void publishAndForget​(io.vertx.servicediscovery.Record record)
        Variant of publish(Record) that ignores the result of the operation.

        This method subscribes on the result of publish(Record), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from publish(Record) but you don't need to compose it with other operations.

        Parameters:
        record - the record
      • unpublish

        public io.smallrye.mutiny.Uni<Void> unpublish​(String id)
        Un-publishes a record.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        id - the registration id
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • unpublishAndAwait

        public Void unpublishAndAwait​(String id)
        Blocking variant of unpublish(String).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        id - the registration id
        Returns:
        the Void instance produced by the operation.
      • unpublishAndForget

        public void unpublishAndForget​(String id)
        Variant of unpublish(String) that ignores the result of the operation.

        This method subscribes on the result of unpublish(String), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from unpublish(String) but you don't need to compose it with other operations.

        Parameters:
        id - the registration id
      • getRecord

        public io.smallrye.mutiny.Uni<io.vertx.servicediscovery.Record> getRecord​(io.vertx.core.json.JsonObject filter)
        Lookups for a single record.

        Filters are expressed using a Json object. Each entry of the given filter will be checked against the record. All entry must match exactly the record. The entry can use the special "*" value to denotes a requirement on the key, but not on the value.

        Let's take some example:

           { "name" = "a" } => matches records with name set fo "a"
           { "color" = "*" } => matches records with "color" set
           { "color" = "red" } => only matches records with "color" set to "red"
           { "color" = "red", "name" = "a"} => only matches records with name set to "a", and color set to "red"
         

        If the filter is not set (null or empty), it accepts all records.

        This method returns the first matching record.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        filter - the filter.
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • getRecordAndAwait

        public io.vertx.servicediscovery.Record getRecordAndAwait​(io.vertx.core.json.JsonObject filter)
        Blocking variant of getRecord(JsonObject).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        filter - the filter.
        Returns:
        the Record instance produced by the operation.
      • getRecordAndForget

        public void getRecordAndForget​(io.vertx.core.json.JsonObject filter)
        Variant of getRecord(JsonObject) that ignores the result of the operation.

        This method subscribes on the result of getRecord(JsonObject), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from getRecord(JsonObject) but you don't need to compose it with other operations.

        Parameters:
        filter - the filter.
      • getRecord

        public io.smallrye.mutiny.Uni<io.vertx.servicediscovery.Record> getRecord​(String id)
        Looks up for a single record by its registration id.

        When there are no matching record, the operation succeeds, but the async result has no result (null).

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        id - the registration id
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • getRecordAndAwait

        public io.vertx.servicediscovery.Record getRecordAndAwait​(String id)
        Blocking variant of getRecord(String).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        id - the registration id
        Returns:
        the Record instance produced by the operation.
      • getRecordAndForget

        public void getRecordAndForget​(String id)
        Variant of getRecord(String) that ignores the result of the operation.

        This method subscribes on the result of getRecord(String), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from getRecord(String) but you don't need to compose it with other operations.

        Parameters:
        id - the registration id
      • getRecord

        public io.smallrye.mutiny.Uni<io.vertx.servicediscovery.Record> getRecord​(Function<io.vertx.servicediscovery.Record,​Boolean> filter)
        Lookups for a single record.

        The filter is a taking a Record as argument and returning a boolean. You should see it as an accept method of a filter. This method return a record passing the filter.

        This method only looks for records with a UP status.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        filter - the filter, must not be null. To return all records, use a function accepting all records
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • getRecordAndAwait

        public io.vertx.servicediscovery.Record getRecordAndAwait​(Function<io.vertx.servicediscovery.Record,​Boolean> filter)
        Blocking variant of io.vertx.mutiny.servicediscovery.ServiceDiscovery#getRecord(Function).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        filter - the filter, must not be null. To return all records, use a function accepting all records
        Returns:
        the Record instance produced by the operation.
      • getRecordAndForget

        public void getRecordAndForget​(Function<io.vertx.servicediscovery.Record,​Boolean> filter)
        Variant of io.vertx.mutiny.servicediscovery.ServiceDiscovery#getRecord(Function) that ignores the result of the operation.

        This method subscribes on the result of io.vertx.mutiny.servicediscovery.ServiceDiscovery#getRecord(Function), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from io.vertx.mutiny.servicediscovery.ServiceDiscovery#getRecord(Function) but you don't need to compose it with other operations.

        Parameters:
        filter - the filter, must not be null. To return all records, use a function accepting all records
      • getRecord

        public io.smallrye.mutiny.Uni<io.vertx.servicediscovery.Record> getRecord​(Function<io.vertx.servicediscovery.Record,​Boolean> filter,
                                                                                  boolean includeOutOfService)
        Lookups for a single record.

        The filter is a taking a Record as argument and returning a boolean. You should see it as an accept method of a filter. This method return a record passing the filter.

        Unlike getRecord(io.vertx.core.json.JsonObject), this method may accept records with a OUT OF SERVICE status, if the includeOutOfService parameter is set to true.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        filter - the filter, must not be null. To return all records, use a function accepting all records
        includeOutOfService - whether or not the filter accepts OUT OF SERVICE records
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • getRecordAndAwait

        public io.vertx.servicediscovery.Record getRecordAndAwait​(Function<io.vertx.servicediscovery.Record,​Boolean> filter,
                                                                  boolean includeOutOfService)
        Blocking variant of io.vertx.mutiny.servicediscovery.ServiceDiscovery#getRecord(Function,boolean).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        filter - the filter, must not be null. To return all records, use a function accepting all records
        includeOutOfService - whether or not the filter accepts OUT OF SERVICE records
        Returns:
        the Record instance produced by the operation.
      • getRecordAndForget

        public void getRecordAndForget​(Function<io.vertx.servicediscovery.Record,​Boolean> filter,
                                       boolean includeOutOfService)
        Variant of io.vertx.mutiny.servicediscovery.ServiceDiscovery#getRecord(Function,boolean) that ignores the result of the operation.

        This method subscribes on the result of io.vertx.mutiny.servicediscovery.ServiceDiscovery#getRecord(Function,boolean), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from io.vertx.mutiny.servicediscovery.ServiceDiscovery#getRecord(Function,boolean) but you don't need to compose it with other operations.

        Parameters:
        filter - the filter, must not be null. To return all records, use a function accepting all records
        includeOutOfService - whether or not the filter accepts OUT OF SERVICE records
      • getRecords

        public io.smallrye.mutiny.Uni<List<io.vertx.servicediscovery.Record>> getRecords​(io.vertx.core.json.JsonObject filter)
        Lookups for a set of records. Unlike getRecord(io.vertx.core.json.JsonObject), this method returns all matching records.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        filter - the filter - see getRecord(io.vertx.core.json.JsonObject)
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • getRecordsAndAwait

        public List<io.vertx.servicediscovery.Record> getRecordsAndAwait​(io.vertx.core.json.JsonObject filter)
        Blocking variant of getRecords(JsonObject).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        filter - the filter - see getRecord(io.vertx.core.json.JsonObject)
        Returns:
        the List instance produced by the operation.
      • getRecords

        public io.smallrye.mutiny.Uni<List<io.vertx.servicediscovery.Record>> getRecords​(Function<io.vertx.servicediscovery.Record,​Boolean> filter)
        Lookups for a set of records. Unlike getRecord(io.vertx.core.json.JsonObject), this method returns all matching records.

        The filter is a taking a Record as argument and returning a boolean. You should see it as an accept method of a filter. This method return a record passing the filter.

        This method only looks for records with a UP status.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        filter - the filter, must not be null. To return all records, use a function accepting all records
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • getRecordsAndAwait

        public List<io.vertx.servicediscovery.Record> getRecordsAndAwait​(Function<io.vertx.servicediscovery.Record,​Boolean> filter)
        Blocking variant of io.vertx.mutiny.servicediscovery.ServiceDiscovery#getRecords(Function).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        filter - the filter, must not be null. To return all records, use a function accepting all records
        Returns:
        the List instance produced by the operation.
      • getRecordsAndForget

        public void getRecordsAndForget​(Function<io.vertx.servicediscovery.Record,​Boolean> filter)
        Variant of io.vertx.mutiny.servicediscovery.ServiceDiscovery#getRecords(Function) that ignores the result of the operation.

        This method subscribes on the result of io.vertx.mutiny.servicediscovery.ServiceDiscovery#getRecords(Function), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from io.vertx.mutiny.servicediscovery.ServiceDiscovery#getRecords(Function) but you don't need to compose it with other operations.

        Parameters:
        filter - the filter, must not be null. To return all records, use a function accepting all records
      • getRecords

        public io.smallrye.mutiny.Uni<List<io.vertx.servicediscovery.Record>> getRecords​(Function<io.vertx.servicediscovery.Record,​Boolean> filter,
                                                                                         boolean includeOutOfService)
        Lookups for a set of records. Unlike getRecord(io.vertx.core.json.JsonObject), this method returns all matching records.

        The filter is a taking a Record as argument and returning a boolean. You should see it as an accept method of a filter. This method return a record passing the filter.

        Unlike getRecords(io.vertx.core.json.JsonObject), this method may accept records with a OUT OF SERVICE status, if the includeOutOfService parameter is set to true.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        filter - the filter, must not be null. To return all records, use a function accepting all records
        includeOutOfService - whether or not the filter accepts OUT OF SERVICE records
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • getRecordsAndAwait

        public List<io.vertx.servicediscovery.Record> getRecordsAndAwait​(Function<io.vertx.servicediscovery.Record,​Boolean> filter,
                                                                         boolean includeOutOfService)
        Blocking variant of io.vertx.mutiny.servicediscovery.ServiceDiscovery#getRecords(Function,boolean).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        filter - the filter, must not be null. To return all records, use a function accepting all records
        includeOutOfService - whether or not the filter accepts OUT OF SERVICE records
        Returns:
        the List instance produced by the operation.
      • getRecordsAndForget

        public void getRecordsAndForget​(Function<io.vertx.servicediscovery.Record,​Boolean> filter,
                                        boolean includeOutOfService)
        Variant of io.vertx.mutiny.servicediscovery.ServiceDiscovery#getRecords(Function,boolean) that ignores the result of the operation.

        This method subscribes on the result of io.vertx.mutiny.servicediscovery.ServiceDiscovery#getRecords(Function,boolean), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from io.vertx.mutiny.servicediscovery.ServiceDiscovery#getRecords(Function,boolean) but you don't need to compose it with other operations.

        Parameters:
        filter - the filter, must not be null. To return all records, use a function accepting all records
        includeOutOfService - whether or not the filter accepts OUT OF SERVICE records
      • update

        public io.smallrye.mutiny.Uni<io.vertx.servicediscovery.Record> update​(io.vertx.servicediscovery.Record record)
        Updates the given record. The record must has been published, and has it's registration id set.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        record - the updated record
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • updateAndAwait

        public io.vertx.servicediscovery.Record updateAndAwait​(io.vertx.servicediscovery.Record record)
        Blocking variant of update(Record).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        record - the updated record
        Returns:
        the Record instance produced by the operation.
      • updateAndForget

        public void updateAndForget​(io.vertx.servicediscovery.Record record)
        Variant of update(Record) that ignores the result of the operation.

        This method subscribes on the result of update(Record), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from update(Record) but you don't need to compose it with other operations.

        Parameters:
        record - the updated record
      • bindings

        public Set<ServiceReference> bindings()
        Returns:
        the set of service references retrieved by this service discovery.
      • options

        public io.vertx.servicediscovery.ServiceDiscoveryOptions options()
        Returns:
        the discovery options. Modifying the returned object would not update the discovery service configuration. This object should be considered as read-only.
      • releaseServiceObject

        public static void releaseServiceObject​(ServiceDiscovery discovery,
                                                Object svcObject)
        Parameters:
        discovery - the service discovery
        svcObject - the service object
      • newInstance

        public static ServiceDiscovery newInstance​(io.vertx.servicediscovery.ServiceDiscovery arg)