This sample describes how to use spring-cloud-feature-management to manage features and how to get configurations from Azure Configuration Service to Spring Environment.
- A Java Development Kit (JDK), version 8.
- Apache Maven, version 3.0 or later.
Start the application and check the resulting console output to check the returned value.
- Build and run the sample.
mvn package spring-boot:run
- Goto localhost:8080
- A website will load with headers; Home, Beta, and Privacy. The Beta tab will only show when Beta is true. When the Beta tab is selected in will bring you two one of two pages BetaA or BetaB which is determined by the RandomFilter. Selecting the Privacy tab show shows how FeatureManagementSnapshot works. Again the RandomFilter is used, but each section has it called individually, but it will return the same result for each.
- Goto localhost:8080/?User=Jeff
- The same homepage will show, but a new tab is shown Target. The Target tab shows when the TargetingFilter returns true for the target feature flag. The TargetingFilter conditions are configured in
application.yml
. In this example the Target tab will show for users Jeff and Alicia, and groups Ring0 and Ring1. No one else will see the targeting tab. - Going to
TargetingContextAccessor
you will see that the currentTargetingContext
is configured to have the UserId and groups to match therequestContext.getParameter("User");
andrequestContext.getParameter("Group");
respectively.TargetingContextAccessor
is user defined so any method can be used to set these values.
-
Create a Configuration Store if not exist.
-
Import the data file src/main/resources/data/sample-data.json into the Configuration Store created above. Under
For language
selectOther
. UnderFile type
selectYaml
.
Change the connection-string value with the Access Key value of the Configuration Store created above.
Start the application and access http://localhost:8080 to check the returned value. Different commands for different scenarios are listed below.
- Load properties similar with from application.properties, i.e., keys starting with /application/
$ mvn spring-boot:run
- Load properties similar with from application_dev.properties, i.e., keys starting with /application_dev
$ mvn -Dspring.profiles.active=dev spring-boot:run
- Load properties similar with from foo.properties, i.e., keys starting with /foo/
$ mvn -Dspring.application.name=foo spring-boot:run
- Load properties similar with from foo_dev.properties, i.e., keys starting with /foo_dev/
$ mvn -Dspring.application.name=foo -Dspring.profiles.active=dev spring-boot:run
Please refer to this README about more usage details.