https://mp.weixin.qq.com/s/2A1EAdpWYrUorFm3c--iSQ
关于 feature toggle,各种语言有不同的实现,具体请参见这里:
http://featureflags.io/resources/
在Java中,较常用的是 Togglz。
public enum MyFeatures implements Feature { @EnabledByDefault @Label("First Feature") FEATURE_ONE, @Label("Second Feature") FEATURE_TWO; public boolean isActive() { return FeatureContext.getFeatureManager().isActive(this); } }
The next step is to create an implementation of
TogglzConfig
:@ApplicationScoped public class DemoConfiguration implements TogglzConfig { public Class<? extends Feature> getFeatureClass() { return MyFeatures.class; } public StateRepository getStateRepository() { return new FileBasedStateRepository(new File("/tmp/features.properties")); } public UserProvider getUserProvider() { return new ServletUserProvider("admin"); } }
getStateRepository()
: This method must return the feature state repository which is responsible to persist the state of features. This example uses theFileBasedStateRepository
which uses Java property files to save the feature state. But Toggles provides several other implementations. Please refer to State Repositories for details.getUserProvider()
: This method returns a provider class that is responsible to tell the FeatureManager which is the current user. Togglz provides out-of-the-box integration with many popular security frameworks. Please refer to User Authentication for details.