17 Ekim 2022 Pazartesi

Feature Flags veya Feature toggles - Runtime Feature Toggling

Giriş
Martin Fowler'ın  açıklaması şöyle
A powerful technique, allowing teams to modify system behavior without changing code.

1. Unleash Kütüphanesi
Gitlab ile hazır geliyor. Tek yapmamız gerek Gitlab üzerinde bir Feature Flag yaratmak. Eğer Gitlab kullanımıyotsak Unleash sunucusunu bizim çalıştırmamız gerekiyor.

Maven
Şu satırı dahil ederiz
<dependency>
<groupId>io.getunleash</groupId> <artifactId>unleash-client-java</artifactId> <version>6.1.0</version> </dependency>
Bir bean yaratırız
@Bean
public Unleash unleash () {
  UnleashConfig unleashConfig = UnleashConfig.builder()
    .appName(APP_DEPLOYMENT_ENVIRONMENT)
    .instanceId(INSTANCE_ID)
    .unleashAPI(GITLAB_UNLEASH_URL)
    .build();
  return new DefaultUnleash(unleashConfig);
}
Açıklaması şöyle
APP_DEPLOYMENT_ENVIRONMENT : The environment in which the application will be ran. Note this should also be one of the environments scopes configured on the Feature Flag. This value can be automatically populated from the spring-active-profile production, staging, qa etc or you can make it an environment variable in the various environments.
INSTANCE_ID: The gitlab unleash instance id.
GITLAB_UNLEASH_URL: The API URL as shown in the below image.
Kullanmak için şöyle yaparız
@Autowired
private Unleash unleash

...

if(unleash.isEnabled("new-feature-a")) {
  log.info("Executing new-feature-a");
} else {
  log.info("Still running old feature");
}
2. togglz Kütüphanesi
İlk defa burada gördüm

Maven
Şu satırı dahil ederiz
<dependency>
<groupId>org.togglz</groupId>
<artifactId>togglz-spring-boot-starter</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.togglz</groupId>
<artifactId>togglz-console</artifactId>
<version>3.2.1</version>
</dependency>



Hiç yorum yok:

Yorum Gönder