Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BAEL-8955] by sgrverma23:Implement Feature Flags in Java with unleash #18107

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions spring-boot-modules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<module>spring-boot-data</module>
<module>spring-boot-environment</module>
<module>spring-boot-exceptions</module>
<module>spring-boot-featureFlag-Unleash</module>
<module>spring-boot-flowable</module>
<module>spring-boot-graphql</module>
<!--<module>spring-boot-groovy</module>--> <!-- failing after upgrading to jdk17-->
Expand Down
2 changes: 2 additions & 0 deletions spring-boot-modules/spring-boot-featureFlag-Unleash/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

### Relevant Articles:
59 changes: 59 additions & 0 deletions spring-boot-modules/spring-boot-featureFlag-Unleash/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-boot-featureFlag-Unleash</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-boot-featureFlag-Unleash</name>
<description>Demo project for Spring Boot FeatureFlag with Unleash</description>

<parent>
<groupId>com.baeldung.spring-boot-modules</groupId>
sgrverma23 marked this conversation as resolved.
Show resolved Hide resolved
<artifactId>spring-boot-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.getunleash</groupId>
<artifactId>unleash-client-java</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>--enable-preview</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>

<properties>
<java.version>21</java.version>
<springdoc.version>2.2.0</springdoc.version>
<start-class>com.baeldung.DemoApplication</start-class>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.baeldung;

import io.getunleash.DefaultUnleash;
import io.getunleash.Unleash;
import io.getunleash.util.UnleashConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {

public static void main(String[] args) throws InterruptedException {
String appName = "unleash-onboarding-java";
String appInstanceID ="unleash-onboarding-instance";
String appServerUrl = "http://localhost:4242/api/";
String appToken = "<AddYourAPITokenHere>";

SpringApplication.run(DemoApplication.class, args);
UnleashConfig config = UnleashConfig.builder()
.appName(appName)
.instanceId(appInstanceID)
.unleashAPI(appServerUrl)
.apiKey(appToken)
.build();

Unleash unleash = new DefaultUnleash(config);
while(true) {
if (unleash.isEnabled("testDemoFeatureFlag")) {
System.out.println("New feature is enabled!");
} else {
System.out.println("New feature is disabled!");
}
Thread.sleep(1000);
}
}

}