Discovery

Helidon Discovery Support

Overview

In Helidon, discovery is the general process of finding named sets of advertised resources at a moment of an application’s runtime. The advertised resources are often URIs representing microservice endpoints. In some environments, those endpoints might frequently come and go at unpredictable intervals, as microservices are started, stopped, and redeployed. The named applications they represent, however, are relatively static. Discovery helps link such a named application to its transient resources, so that clients can more easily contact it, knowing only its name.

Helidon Discovery is a feature with a vendor- and implementation-independent API backed by vendor-specific implementations of that API known as providers. A developer programs against the Discovery API, and packages a (normally Helidon-supplied) conformant Discovery implementation (a provider) with her application at deployment time. See Providers below.

Maven Coordinates

To enable Helidon Discovery, add the following dependency to your project’s pom.xml (see Managing Dependencies).

pom.xml
<dependencies>
    <dependency>
        <groupId>io.helidon.discovery</groupId>
        <artifactId>helidon-discovery</artifactId>1
    </dependency>
</dependencies>
  1. Helidon Discovery API dependency.

Discovery is implemented by one or more

discovery providers. Generally you will choose a single provider and include its relevant dependencies on your runtime classpath as well. See the Providers section for more details.

API Usage

To use Helidon Discovery, you acquire an io.helidon.discovery.Discovery object and call its uris(String, URI) method to find resources represented as io.helidon.discovery.DiscoveredUri instances. You supply a discovery name, which is the name under which you expect to find advertised resources, and a default value, which is a URI to use in case the provider does not supply any resources. In general, DiscoveredUris you receive are ordered from more suitable to less suitable, where the definition of suitable is up to the provider. Some providers consider aspects like the health or uptime of an advertised resource when returning results. Others may not. Finally, a DiscoveredUri representing the default value you supply will always be present as the last element in the set of resources you receive.

Discovery Acquisition

Discovery Acquisition Using Helidon Inject

You can acquire a io.helidon.discovery.Discovery object by injecting it into your Helidon application:

Acquiring a Discovery object using Helidon Inject

import java.util.Objects;
import io.helidon.discovery.Discovery;
import io.helidon.service.registry.Service;

public class MyClass {

    private final Discovery discovery;

    @Service.Inject1
    public MyClass(Discovery discovery) {2
        this.discovery = discovery;3
    }
}
  1. Use the io.helidon.service.registry.Service.Inject annotation to indicate that this constructor has an injection point.
  2. Here, the discovery constructor parameter is the injection point and will receive a non-null instance of io.helidon.discovery.Discovery.
  3. The constructor explicitly assigns the injected reference to the discovery instance field.

Acquiring Discovery Using Service Registry

You can acquire a io.helidon.discovery.Discovery object by using the Helidon Service Registry via the io.helidon.service.registry.Services façade:

Acquiring a Discovery object using the Helidon Service Registry

import io.helidon.discovery.Discovery;
import io.helidon.service.registry.Services;

public class MyOtherClass {

    private final Discovery discovery;

    public MyOtherClass() {
        this.discovery = Services.get(Discovery.class);1
    }

}
  1. Use the io.helidon.service.registry.Services#get(Class) method to acquire an instance of the io.helidon.discovery.Discovery class, and assign it to an instance field.

Discovering URIs

Discovery uses a discovery name to identify and discover URIs notionally belonging to an application. An application may have several URIs. The discovery name is the name that identifies the application for discovery purposes.

To discover a named application’s URIs, call the Discovery#uris(String, URI) method, passing it the discovery name and a URI to use as a default value. Both values must be non-null. You will receive an immutable SequencedSet of io.helidon.discovery.DiscoveredUri instances representing the URIs, ordered from the most to the least suitable, according to the provider. A DiscoveredUri representing the default value will appear last in the set:

Discovering URIs

import java.net.URI;
import java.util.SequencedSet;
import io.helidon.discovery.DiscoveredUri;
import io.helidon.discovery.Discovery;

SequencedSet<DiscoveredUri> uris =1
    discovery.uris("EXAMPLE",2
        URI.create("http://example.com/"));3
URI uri = uris.getFirst().uri();4
  1. URIs that are discovered are represented as a SequencedSet of io.helidon.discovery.DiscoveredUri instances. This is the discovered set. In general, the first element in the set is the discovered URI that is the most suitable, as determined by the Discovery provider. (The last element is a DiscoveredUri whose uri() method yields a URI that is identical or equal to the URI that was supplied as the default value.)
  2. EXAMPLE is the discovery name for which URIs are being sought.
  3. This URI is a default value in case the Discovery provider finds no URIs, or encounters an error. A DiscoveredUri representing it will appear last in the discovered set.
  4. This URI is the most suitable one for use, and may or may not be equal to the supplied default value.

Providers

The Discovery API is implemented at runtime by a Discovery provider.

To use a Discovery provider, include it on your runtime classpath. See the provider’s documentation for details about installing, configuring, and using the provider.

WebClient Integration

Helidon integrates a Discovery provider with Web Client.

Maven Coordinates

To include the Helidon Web Client Discovery integration in your project, add the Web Client Discovery integration dependency (see Managing Dependencies). Any Discovery provider you use must also be present on the runtime classpath.

pom.xml

pom.xml
<dependencies>
    <dependency>
        <groupId>io.helidon.webclient</groupId>
        <artifactId>helidon-webclient-discovery</artifactId>
        <scope>runtime</scope>
    </dependency>
</dependencies>

The behavior of the Web Client Discovery integration is fully specified and documented.

Configuration

The Helidon Web Client Discovery integration can be configured using Helidon Config. Examples shown below are in YAML, but are expressible in any format and any location that Helidon Config supports.

Because the Helidon Web Client Discovery integration is fundamentally a Web Client Service, you configure it under a Web Client’s services configuration node:

application.yaml
webclient:
  services:
    discovery:1
  1. Indicates that the Web Client Discovery integration should apply to this Web Client configuration. More configuration is required; see below.

Configuring URIs

To mark URIs requested by a Web Client as subject to discovery, and to use discovery names appropriate for them, you need to configure prefix URIs. URIs that match no prefix will not be subject to discovery:

application.yaml
webclient:
  services:
    discovery:
      prefix-uris:
        EXAMPLE: "https://example.com:443/"1
        TEST: "https://test.example.com:443/"23
  1. Indicates that URIs starting with example prefix URI will be subject to discovery, using the discovery name of EXAMPLE
  2. Indicates that URIs starting with test prefix URI will be subject to discovery, using the discovery name of TEST
  3. URIs that begin with text other than example prefix URI or test prefix URI will not be subject to discovery

Reference

Copyright © 2018, 2026 Oracle and/or its affiliates.