Skip to content

Latest commit

 

History

History
70 lines (51 loc) · 2.29 KB

README.md

File metadata and controls

70 lines (51 loc) · 2.29 KB

ConfigCat OpenFeature Provider for Java

ConfigCat OpenFeature Provider can provide usage for ConfigCat via the OpenFeature Java SDK.

Installation

<dependency>
    <groupId>dev.openfeature.contrib.providers</groupId>
    <artifactId>configcat</artifactId>
    <version>0.1.1</version>
</dependency>

Usage

The ConfigCat OpenFeature Provider uses a ConfigCat Java SDK client for evaluating feature flags.

Usage Example

The following example shows how to use the provider with the OpenFeature SDK.

// Build options for the ConfigCat SDK.
ConfigCatProviderConfig configCatProviderConfig = ConfigCatProviderConfig.builder()
        .sdkKey("#YOUR-SDK-KEY#")
        .options(options -> {
            options.pollingMode(PollingModes.autoPoll());
            options.logLevel(LogLevel.WARNING);
            // ...
        })
        .build();

ConfigCatProvider configCatProvider = new ConfigCatProvider(configCatProviderConfig);

// Configure the provider.
OpenFeatureAPI.getInstance().setProviderAndWait(configCatProvider);

// Create a client.
Client client = OpenFeatureAPI.getInstance().getClient();

// Evaluate your feature flag.
boolean isAwesomeFeatureEnabled = client.getBooleanValue("isAwesomeFeatureEnabled", false);

// With evaluation context.
MutableContext context = new MutableContext();
context.setTargetingKey("#SOME-USER-ID#");
context.add("Email", "[email protected]");
context.add("Country", "CountryID");
context.add("Rating", 4.5);

boolean isAwesomeFeatureEnabled = client.getBooleanValue("isAwesomeFeatureEnabled", false, context);

For a full list of configuration options see the ConfigCat Java SDK documentation.

Notes

The underlying ConfigCat Client is accessible via the provider's getConfigCatClient() function:

configCatProvider.getConfigCatClient()...

ConfigCat Provider Test Strategy

Unit tests are based on the SDK's local file override feature.
See ConfigCatProviderTest.java for more information.