helidon-io / helidon

Java libraries for writing microservices
https://helidon.io
Apache License 2.0
3.52k stars 564 forks source link

Helidon Jersey Connector auto discovered configuration #7349

Open romain-grecourt opened 1 year ago

romain-grecourt commented 1 year ago

Helidon Version: 4.0.0-M1


Currently the Helidon Jersey Connector can only configure the underlying WebClient by looking up a JAXRS client property named jersey.connector.helidon.config.

client.property(HelidonProperties.CONFIG, Config.create().get("client"))

When using MicroProfile rest client programmatically we can also set the property:

RestClientBuilder.newBuilder()
    .property(HelidonProperties.CONFIG, Config.create().get("rest-client"))

However when using CDI, it's not possible to pass configuration without implementing a feature:

@ConstrainedTo(RuntimeType.CLIENT)
@Provider
public class HelidonConnectorConfigFeature implements Feature {

    private final LazyValue<Config> config = LazyValue.create(() -> Config.create().get("rest-client"));

    @Override
    public boolean configure(FeatureContext context) {
        context.property(HelidonProperties.CONFIG, config.get());
        return true;
    }
}

Since config is now available statically, we should provide the feature above out of the box. Perhaps also support MicroProfile config.

tomas-langer commented 1 year ago

Please use LazyValue.create(GlobalConfig::config); instead to obtain configuration. We should also register GlobalConfig from MP startup when we create an instance of MP configuration that will be used, so we have a consistent config.

romain-grecourt commented 1 year ago

Also, we need to consider having support for microprofile. And we should also considering moving the jersey integration under microprofile so that we can do all the microprofile glue without having conflicting dependencies.

tomas-langer commented 1 year ago

we do not need to use MP APIs, if we configured GlobalConfig correctly in MP (the glue code is then only in MP).

romain-grecourt commented 1 year ago

Roger that. This means that If the Helidon MicroProfile server sets GlobalConfig properly, then the connector config feature can support MicroProfile config indirectly.


GlobalConfig.config() always returns a value:

public static Config config() {
    return configured() ? CONFIG.get() : DEFAULT_CONFIG.get();
}

If the feature is invoked before GlobalConfig is initialized by the MicroProfile server, then it will use the default config.

Also if the feature is used in a non server application, then GlobalConfig will have to be initialized manually in order to support MicroProfile config.