I have two application - api
and dashboard
. Both of these applications use the same Features from the same database. Togglz console is only active in dashboard
application. The issue is that when I change the state of the feature in my dashboard
application, api
application is not immediately aware about that. I need to restart my api
in order to refresh the features state.
Is it possible to notify api
application about changes of feature state without restarting?
UPDATED - Togglz configuration added
This is the a base configuration in my Maven common
project(api
and dashboard
projects depend on this one):
@Configuration
public class FeatureToggleConfiguration {
@Autowired
private DataSource dataSource;
@Bean
public FeatureManager getFeatureManager() {
// @formatter:off
FeatureManager featureManager = new FeatureManagerBuilder()
.stateRepository(new CachingStateRepository(new JDBCStateRepository(dataSource)))
.featureEnum(ApplicationFeatures.class)
.userProvider(new SpringSecurityUserProvider(Authority.Type.ROLE_ADMIN.getName()))
.build();
// @formatter:on
return featureManager;
}
}
ApplicationFeatures
(also placed in common
project):
public enum ApplicationFeatures implements Feature {
// @formatter:off
@EnabledByDefault
@Label("Log Events Feature")
LOG_EVENT_FEATURE,
@EnabledByDefault
@Label("Log Ok Sessions Feature")
LOG_OK_SESSIONS_FEATURE,
@EnabledByDefault
@Label("Log HTTP Requests Data Feature")
LOG_HTTP_REQUESTS_DATA_FEATURE;
// @formatter:on
public boolean isActive() {
return FeatureContext.getFeatureManager().isActive(this);
}
}
This is DashboardFeatureToggleConfiguration
(for Togglz web console) from my dashboard
project:
@Configuration
public class DashboardFeatureToggleConfiguration {
@Bean
public ServletRegistrationBean getTogglzConsole() {
ServletRegistrationBean servlet = new ServletRegistrationBean();
servlet.setName("TogglzConsole");
servlet.setServlet(new TogglzConsoleServlet());
servlet.setUrlMappings(Collections.singletonList("/togglz/*"));
return servlet;
}
}
You are using CachingStateRepository
which is causing the problem your are describing. You have basically two options:
First you could remove the CachingStateRepository
and use JDBCStateRepository
directly. This way you will have much more hits on the database but this may be acceptable. So your configuration would look like this:
.stateRepository(new JDBCStateRepository(dataSource))
Our you could specify the TTL value for the CachingStateRepository
which means that the cached entries will be cached only for a specific time:
.stateRepository(
new CachingStateRepository(new JDBCStateRepository(dataSource), 10000)
)
In this example the TTL is set to 10000 which means that the feature state will only be cached for 10 seconds.