Skip to content

Instantly share code, notes, and snippets.

@schroedermatt
Created April 4, 2022 20:38
Show Gist options
  • Select an option

  • Save schroedermatt/4324d66bd7e2a1fd58161833693416ba to your computer and use it in GitHub Desktop.

Select an option

Save schroedermatt/4324d66bd7e2a1fd58161833693416ba to your computer and use it in GitHub Desktop.
/**
* Configure the client that connects to Unleash if unleash.enabled is "true"
**/
@Bean
@ConditionalOnProperty(value = "unleash.enabled", havingValue = "true")
Unleash defaultUnleash() {
UnleashConfig config = UnleashConfig.builder()
.unleashAPI("<http://unleash-api.com>")
.instanceId("asdf-123")
.appName("unleash-demo")
.environment("development")
.fetchTogglesInterval(10)
.subscriber(new Log4JSubscriber())
.build();
return new Unleash(config);
}
/**
* If unleash.enabled is false, the above bean will not be created.
* In this scenario, the FakeUnleash client will be injected into the
* app context for use. This is helpful for local development.
**/
@Bean
@ConditionalOnMissingBean(Unleash.class)
Unleash fakeUnleash() {
return new FakeUnleash(config);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment