11# Dropwizard Openfeature
22
3- This plugin integrates [ openfeature] ( https://openfeature.dev/ ) with dropwizard and allows you to use openfeature feature
3+ This plugin integrates [ openfeature] [ 1 ] with dropwizard and allows you to use openfeature feature
44flags, provided by supported openfeature providers via a managed ` OpenFeatureAPI ` instance.
55
6- Currently only [ flagd] ( https://flagd.dev/ ) and the SDKs
7- [ InMemoryProvider] ( https://github.com/open-feature/java-sdk/blob/main/src/main/java/dev/openfeature/sdk/providers/memory/InMemoryProvider.java )
8- providers are supported
6+ Currently only [ flagd] [ 2 ] and the SDKs [ InMemoryProvider] [ 3 ] providers are supported
97
10- ## Installing the bundle from source code
8+ ## Installing the bundle
9+
10+ ### Releases from maven central
11+
12+ [ io.github.sideshowcoder/dropwizard-openfeature] [ 4 ]
13+
14+ ``` xml
15+ <dependency >
16+ <groupId >io.github.sideshowcoder</groupId >
17+ <artifactId >dropwizard-openfeature</artifactId >
18+ <version >0.0.2</version >
19+ </dependency >
20+ ```
21+
22+ ### Snapshots form source
1123
1224```
1325git clone https://github.com/sideshowcoder/dropwizard-openfeature
1426cd dropwizard-openfeature
1527./mvn install
1628```
1729
18- After installing the plugin locally you can include it in your pom.xml
30+ After installing the plugin locally you can include it in your ` pom.xml `
1931
2032``` xml
2133<dependency >
2234 <groupId >io.github.sideshowcoder</groupId >
2335 <artifactId >dropwizard-openfeature</artifactId >
24- <version >$VERSION </version >
36+ <version >0.0.3-SNAPSHOT </version >
2537</dependency >
2638```
2739
40+
41+
2842## Included in the bundle
2943
3044### Supported providers
3145
3246The bundle currently supports both the SDK included ` InMemoryProvider ` as well as ` flagd ` , the provider can be selected
3347via the configuration. For details on the configuration options see ` FlagdConfiguration ` as well the
34- [ flagd documentation] ( https://flagd.dev/providers/java/ ) .
48+ [ flagd documentation] [ 5 ] .
3549
3650### OpenFeatureAPI management
3751
38- The initialized ` OpenFeatureAPI ` is managed via the dropwizard lifecycle.
52+ The initialized ` OpenFeatureAPI ` is managed via the dropwizard lifecycle and will be shutdown gracefully upon
53+ application shutdown, see ` OpenFeatureAPIManager ` .
3954
4055### Healthcheck
4156
4257By default the bundle registers a healthcheck on the state of the provider configured, this healthcheck can be further
4358configured via the ` OpenFeatureHealthCheckConfiguration ` .
4459
45- ## Activating the bundle: Configuration
60+ ## Activating the bundle
4661
47- Your Dropwizard application configuration class must implement ` OpenFeatureBundleConfiguration ` :
62+ Your Dropwizard application configuration class must implement ` OpenFeatureBundleConfiguration `
4863
49- ## Configuring dropwizard-openfeature in the dropwizard config file
64+ ### Configuring dropwizard-openfeature in the dropwizard config file
5065
5166For a full overview see ` OpenFeatureConfiguration ` , ` OpenFeatureHealthCheckConfiguration ` , and ` FlagdConfiguration ` a
5267minimal configuration for flagd runnining locally on the port 8013 would look as follows.
@@ -63,9 +78,7 @@ For the bundle to have access to the configuration, your application configurati
6378` OpenFeatureBundleConfiguration`.
6479
6580` ` ` java
66- import io.github.sideshowcoder.dropwizard_openfeature.OpenFeatureConfiguration;
67-
68- public class ApplicationConfiguration implements OpenFeatureBundleConfiguration {
81+ public class Config extends Configuration implements OpenFeatureBundleConfiguration {
6982
7083 @Valid
7184 @NotNull
@@ -79,18 +92,88 @@ public class ApplicationConfiguration implements OpenFeatureBundleConfiguration
7992}
8093` ` `
8194
82- # # Activating the bundle: Initialization
95+ # ## Initialization
8396
8497In your application's `initialize` method, call `bootstrap.addBundle(new OpenFeatureBundle())` :
8598
8699` ` ` java
87- import io.github.sideshowcoder.dropwizard_openfeature.OpenFeatureBundle;
100+ public class App extends Application<Config> {
101+
102+ @Override
103+ public void initialize(Bootstrap<MyConfiguration> bootstrap) {
104+ bootstrap.addBundle(new OpenFeatureBundle());
105+ }
106+
107+ @Override
108+ public void run(Config config, Environment environment) throws Exception {
109+ /* ... */
110+ }
111+ }
112+ ` ` `
113+
114+ # ## Using the client
115+
116+ OpenFeature configures a global `OpenFeatureAPI` which grants access to a client, which can be injected as needed, it is
117+ common practise to provide a domain as an identifier, this is however not required, unless multiple clients are to be
118+ created.
119+
120+ ` ` ` java
121+ import dev.openfeature.sdk.OpenFeatureAPI;
122+
123+ public class App extends Application<Config> {
124+
125+ @Override
126+ public void initialize(Bootstrap<MyConfiguration> bootstrap) {
127+ bootstrap.addBundle(new OpenFeatureBundle());
128+ }
129+
130+ @Override
131+ public void run(Config config, Environment environment) throws Exception {
132+ /* ... */
133+ var client = OpenFeatureAPI.getInstance().getClient("my-application-domain");
134+
135+ var myResource = new MyResource(client);
136+ environment.jersey().register(myResource);
137+
138+ var myOtherResource = new MyOtherResource(client);
139+ environment.jersey().register(myResource);
140+ /* ... */
141+ }
142+ }
143+ ` ` `
144+
145+ # ## Accessing the underlying feature provider
146+
147+ The bundle exposes access to the underlying feature provider. Useful for runtime configuration and introspection of the
148+ provider. For example when using the `InMemoryProvider` flags can be updated at runtime for example for testing.
149+
150+ ` ` ` java
151+ public class App extends Application<Config> {
152+
153+ private OpenFeatureBundle bundle;
154+ private InMemoryProvider provider;
88155
89- @Override
90- public void initialize(Bootstrap<MyConfiguration> bootstrap) {
91- bootstrap.addBundle(new OpenFeatureBundle());
156+ @Override
157+ public void initialize(Bootstrap<MyConfiguration> bootstrap) {
158+ bundle = new OpenFeatureBundle();
159+ bootstrap.addBundle(bundle);
160+ }
161+
162+ @Override
163+ public void run(Config config, Environment environment) throws Exception {
164+ // ...
165+ provider = (InMemoryProvider) bundle.getFeatureProvider();
166+ provider.updateFlags(Map.of(/* ... */));
167+ // ...
168+ }
92169}
93170` ` `
94171
95172# Contributors
96173* [Philipp Fehre](https://github.com/sideshowcoder)
174+
175+ [1] : https://openfeature.dev/
176+ [2] : https://flagd.dev/
177+ [3] : https://github.com/open-feature/java-sdk/blob/main/src/main/java/dev/openfeature/sdk/providers/memory/InMemoryProvider.java
178+ [4] : https://central.sonatype.com/artifact/io.github.sideshowcoder/dropwizard-openfeature
179+ [5] : https://flagd.dev/providers/java/
0 commit comments