edit-icon download-icon

Configuration push

Last Updated: Jun 13, 2018

Configuration push in EDAS includes global configuration push and intra-application configuration push based on different permission control. Global configuration push is targeted at all configurations of a specific user, whereas intra-application configuration push is targeted at the configurations of a specific application.

This topic describes intra-application configuration push.

Configuration in EDAS consists of Group, Data ID, and Content.

  • Group: Name of a group, which is created in Service Group and used to isolate services in a namespace. for example, a package in Java. The maximum length allowed is 128 characters.

  • Data ID: Configuration name, for example, a class name in Java. The configuration name contains a maximum of 256 characters.

    A piece of configuration is identified by group and Data ID collectively and corresponds to a value. The names of group and Data ID can contain four types of special characters: period (.), colon (:), hyphen (-), and underscore (_).

  • Content: Configuration value, which may contain a maximum of 1,024 characters.

You can add, modify, and delete configurations in real time, and apply configurations dynamically without the need to modify code, republish services, or restart services.

Note: The group element of configuration push is created in a service group. If no service is created, the configuration page displays the system configuration that is automatically generated. You can ignore this configuration.

Configuration push

  1. Log on to the EDAS console.

  2. Select Applications in the left-side navigation pane.

  3. Click an application name on the Applications page.

  4. Click Configurations in the left-side navigation pane of the Application Details page.

    On this page, you can create, view, update, and delete configuration push within the selected application.

Listen for configuration changes

After you create or update configurations in the EDAS console, you can enable configuration listening in code to keep updated with configuration changes.

Introduce the following dependency to code:

  1. <dependency>
  2. <groupId>com.alibaba.edas.configcenter</groupId>
  3. <artifactId>configcenter-client</artifactId>
  4. <version>1.0.2</version>
  5. </dependency>

Sample code:

  1. import java.io.IOException;
  2. import com.alibaba.edas.configcenter.config.ConfigChangeListener;
  3. import com.alibaba.edas.configcenter.config.ConfigService;
  4. public class ConfigCenter {
  5. // Properties/Switch
  6. private static String config = "";
  7. //Add a configuration listener during initialization
  8. private static void initConfig() {
  9. ConfigService.addListener("YourDataId", "YourGroup",
  10. new ConfigChangeListener() {
  11. public void receiveConfigInfo(String configInfo) {
  12. try {
  13. //Obtain the new configuration after configuration is updated
  14. config = configInfo;
  15. System.out.println(configInfo);
  16. } catch (Exception e) {
  17. e.printStackTrace();
  18. }
  19. }
  20. });
  21. }
  22. public static void main(String[] args) throws IOException {
  23. // This class is equivalent to the init method if Spring is used.
  24. initConfig();
  25. // Prevent the main thread from exiting during the test. If the main thread exits, the daemon thread for configuration subscription also exits.
  26. while (true) {
  27. try {
  28. Thread.sleep(1000);
  29. } catch (InterruptedException e) {
  30. }
  31. }
  32. }
  33. // Use the GET API to expose the configuration value for external use
  34. public static String getConfig() {
  35. return config;
  36. }
  37. }
Thank you! We've received your feedback.