I've just started using FF4j to switch between 2 different API implementations depending on which market the user is on (market = brand/country pair). Here is the code snippet :
@RestController
@RequestMapping("/{brand}/{country}")
public class HomeController {
private final ApiService apiService;
public HomeController(@Qualifier("new-api") ApiService apiService) {
this.apiService = apiService;
}
@GetMapping("/hey")
public String hey(@PathVariable("brand") String brand,
@PathVariable("country") String country) {
return apiService.whichApi();
}
}
interface ApiService {
@Flip(name = "legacy-api", alterBean = "legacy-api")
String whichApi();
}
@Component("new-api")
class NewApiApiService implements ApiService {
@Override
public String whichApi() {
return "NEW_API";
}
}
@Component("legacy-api")
class LegacyApiApiService implements ApiService {
@Override
public String whichApi() {
return "LEGACY_API";
}
}
I created a RegionFlippingStrategy (as the doc says) to define for which market I want to use the legacy-api, but I cannot make it work.
How can I register my new strategy into FF4j ?
How can I switch between API dynamically based on the home controller brand/country inputs ?
How can I register my new strategy into FF4j ?
Let's remind the strategy code
The
FlipStrategyshould be registered in the definition of the featurelegacy-api:xml,yamlorproperties.With the following definition the feature will be enabled only for the granted markets:
How can I switch between API dynamically based on the home controller brand/country inputs ?
The "trick" to is pass the couple brand/country as a single variable
marketin theFlippingExecutionContextand this would help you to understand but here how it works.