简体   繁体   English

FF4J功能切换问题

[英]FF4J feature toggling issue

Currently we are FF4J toggle framework for our Spring based application, where we are using SpringJDBSC store. 当前,我们是基于Spring的应用程序的FF4J切换框架,我们在其中使用SpringJDBSC存储。 Problem is currently we have multiple applications deployed on an enviroment like DEV,UAT etc., the features that are created on enabled or disabled for all the applications in an environment. 问题是当前我们在诸如DEV,UAT等环境中部署了多个应用程序,这些功能是为环境中的所有应用程序启用或禁用时创建的。 Now i want to enable/disable feature per application like the feature "TestFeature" should be ON for App1, and OFF for app2 in DEV enviroment. 现在,我想为每个应用程序启用/禁用功能,例如功能“ TestFeature”对于App1应该为ON,对于DEV环境中的app2应该为OFF。 Any suggestions on how to implement this is really helpful 关于如何实现这一点的任何建议都非常有帮助

  1. Each application you should have a paramter applicationName for you to know if a Feature is toggled or not. 每个应用程序都应有一个参数applicationName以便您了解功能是否已切换。 This value could be the webContext of your application or a property in your configuration file ( application.properties if you use Spring Boot). 该值可以是应用程序的webContext或配置文件中的属性(如果使用Spring Boot,则为application.properties )。

  2. Create a FlippingStrategy evaluating on this value, this look like 创建一个评估此值的FlippingStrategy,如下所示

Sample ApplicationNameStrategy : 示例ApplicationNameStrategy:

public class ApplicationNameStrategy extends AbstractFlipStrategy {

private String currentApplicationName = null;

public ApplicationNameStrategy() {}

public ApplicationNameStrategy() {
    currentApplicationName = //.. init the value here
}

/** {@inheritDoc} */
@Override
public void init(String featureName, Map<String, String> initParams) {
    super.init(featureName, initParams);
}

/** {@inheritDoc} */
@Override
public boolean evaluate(String featureName, FeatureStore store, FlippingExecutionContext executionContext) {
    // special sauce !
    return Arrays.asList(store.read(featureName).getCustomProperty("grantedApplications").split(",")).contains(currentApplicationName);
}
  1. Update your Feature accourdingly 更新您的功能

Sample ff4j.xml snippet 样本ff4j.xml代码段

<feature uid="myFeature" enable="true" description="description" >
   <custom-properties>
    <property name="grantedApplication"
              type="org.ff4j.property.domain.PropertyString" 
              value="appA,appB"  />
    </custom-properties>
    <flipstrategy class="ApplicationNameStrategy">
    </flipstrategy>
</feature>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM