Demo repository for testing features toggles using unleash with a java sdk
This repository contains step-by-step instructions for using feature toggles with the Unleash tool through an SDK in
Java. It also includes a Java application called movies-app
that utilizes the Unleash SDK.
Before you begin, make sure you have the following:
- Java 17 installed and Java 8
- Maven installed
- Docker installed
The movies-app
repository contains a Java application developed with Java 17, JDBC Template, FlywayDB, and classes for
configuring Unleash. It also uses an SDK specifically created for this project. To set up the movies-app
repository,
follow these steps:
-
Clone the repository from the following link: movies-app repository.
-
Open a terminal or command prompt and navigate to the cloned repository's directory.
-
Build the Maven wrapper by running the following command:
mvn -N wrapper:wrapper
-
Build and package the application by running the following command:
./mvnw clean package
The FeatureToggleSdk
repository contains an SDK developed in Java 8 that provides classes and configurations for using
Unleash with toggle names, tenants, companies, or custom fields. To set up the FeatureToggleSdk
repository, follow
these steps:
- Clone the repository from the following link: FeatureToggleSdk repository.
- Open a terminal or command prompt and navigate to the cloned repository's directory.
- Build and publish the SDK to the local Maven repository by running the following command:
dont forget to set java17 for running app-movies and set java8 for build sdk
If you have sdk man:
sdk use java 8.332.08.1
gradle wrapper
./gradlew clean build publishToMavenLocal --info
This command will create a JAR file in the local .m2
repository.
To configure Unleash and create the necessary toggle names and custom fields, follow these steps:
- Start the Unleash server using Docker Compose. Create a
docker-compose.yml
file with the following content:
version: '3.4'
services:
postgres-unleash:
image: postgres:13
container_name: postgres-unleash
environment:
- POSTGRES_USER=unleash_user
- POSTGRES_PASSWORD=password
- POSTGRES_DB=unleash
volumes:
- unleash:/data/postgres
networks:
- unleash
restart: unless-stopped
unleash-server:
image: unleashorg/unleash-server:latest
container_name: unleash-server
environment:
- DATABASE_HOST=postgres-unleash
- DATABASE_NAME=unleash
- DATABASE_USERNAME=unleash_user
- DATABASE_PASSWORD=password
- LOG_LEVEL=INFO
- DATABASE_SSL=false
depends_on:
- postgres-unleash
networks:
- unleash
ports:
- "4242:4242"
tty: false
networks:
unleash:
driver: bridge
volumes:
unleash:
-
Open a terminal or command prompt and navigate to the directory containing the docker-compose.yml file.
-
Start the Unleash server by running the following command:
docker-compose up -d
-
start movies-db:
shell docker compose up postgres
-
start movies-app through an ide (and get fun with breakpoints (: ) or simply by run:
dont forget to set java17 for running app-movies and set java8 for build sdk
If you have sdk man:
sdk use java 17.0.1.12.1-amzn
./mvnw clean package spring-boot:run
Once Unleash is set up and configured, you can test the movies-app application using the following curl commands:
. By Premium:
curl http://localhost:8080/api/v1/movies/premium/tenant/2_cafe | jq
curl http://localhost:8080/api/v1/movies/premium/tenant/2_cafe/company/1_sucursal_devoto | jq
. Custom:
curl http://localhost:8080/api/v1/movies/premium/custom/tenant/2_cafe | jq
curl http://localhost:8080/api/v1/movies/premium/custom/tenant/2_cafe/company/1_sucursal_devoto | jq
To deploy the movies-app application with the SDK, follow these steps:
- Navigate to the movies-app repository's root folder.
- Execute the deploy.sh script. Note that you need to be in the folder containing the script.
./deploy.sh
This script uses the previously created SDK and copies the JAR file into the Docker image.
- After running the script, execute the following command in the root folder of the repository to start the application and its dependencies in Docker:
docker-compose up -d
WIP: Describe the communication process between the Unleash Docker container and the movies-app application.
That's it! You've successfully set up and configured feature toggles with the Unleash tool using the provided SDK and the movies-app application.
Enjoy experimenting with feature flags and managing feature releases in your application.