Skip to content

Commit

Permalink
feat: inject UnleashSubscriber to Unleash bean-definition (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
lbsekr authored Dec 3, 2024
1 parent 5fab8f8 commit aebc91a
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import io.getunleash.Unleash;
import io.getunleash.UnleashContext;
import io.getunleash.UnleashContextProvider;
import io.getunleash.event.UnleashSubscriber;
import io.getunleash.event.NoOpSubscriber;
import io.getunleash.repository.OkHttpFeatureFetcher;
import io.getunleash.strategy.Strategy;
import io.getunleash.util.UnleashConfig;
Expand Down Expand Up @@ -44,7 +46,13 @@ public UnleashContextProvider unleashContextProvider(final UnleashProperties unl
}

@Bean
public Unleash unleash(final UnleashProperties unleashProperties, UnleashContextProvider unleashContextProvider) {
@ConditionalOnMissingBean
public UnleashSubscriber unleashSubscriber() {
return new NoOpSubscriber();
}

@Bean
public Unleash unleash(final UnleashProperties unleashProperties, UnleashContextProvider unleashContextProvider, UnleashSubscriber unleashSubscriber) {
final var provider = getUnleashContextProviderWithThreadLocalSupport(unleashContextProvider);
final var builder = UnleashConfig
.builder()
Expand All @@ -60,6 +68,7 @@ public Unleash unleash(final UnleashProperties unleashProperties, UnleashContext
.sendMetricsReadTimeout(unleashProperties.getSendMetricsReadTimeout())
.customHttpHeader("Authorization", unleashProperties.getApiToken())
.projectName(unleashProperties.getProjectName())
.subscriber(unleashSubscriber)
.synchronousFetchOnInitialisation(unleashProperties.isSynchronousFetchOnInitialisation())
.instanceId(StringUtils.hasText(unleashProperties.getInstanceId()) ? unleashProperties.getInstanceId() :
UUID.randomUUID().toString());
Expand Down

0 comments on commit aebc91a

Please sign in to comment.