Configuration details

Updated at:

Configuration model

The configuration model for Spring Cloud SOFA DRM extends the native model of Dynamic Resource Manager (DRM) with certain constraints.

Configuration property

Description

Domain

Immutable value. Automatically written by the console.

Application

For an application configuration, this is the value of spring.application.name. For a shared configuration, this value is customizable.

Class identity

The default value is application. This is customizable.

Property

Immutable value. Automatically written by the console.

Each application can have multiple dynamic configurations, which are distinguished by their class identity. To simplify the following descriptions, this document covers only customizable items, such as the application and class identity. Fixed properties are not described.

Bootstrap mode

In Bootstrap mode:

  • Spring Cloud SOFA DRM subscribes to three configurations: application, application.{fileExtension}, and application-{profile}.{fileExtension}.

    The priority increases in the following order: application, application.{fileExtension}, and application-{profile}.{fileExtension}. You can configure them as needed.

  • You can use spring.cloud.drm.config.name to configure the class identity. The default value is `application`.

  • You can use spring.cloud.drm.config.file-extension to configure the fileExtension in the class identity. For example, if you set the format to YML, the subscribed configurations become application, application.yml, and application-{profile}.yml. The configuration must also be in the YML file format. DRM supports four configuration formats: properties, YML, JSON, and XML.

  • The configuration prefix for DRM is spring.cloud.sofa.config. The complete configuration options are as follows:

    Configuration item

    Description

    Default value

    name

    The configuration class identity.

    application

    fileExtension

    The configuration format.

    properties

    connectTimeout

    The connection timeout for the initial configuration pull from DRM.

    3000

    timeout

    The read timeout for the initial configuration pull from DRM.

    3000

    refreshEnabled

    Specifies whether to enable configuration refresh.

    true

    extensionConfigs

    Extension configurations.

    None

    sharedConfigs

    Shared configurations.

    None

  • Spring Cloud SOFA DRM supports extension configurations. You can configure them using spring.cloud.drm.config.extension-configs. The following example shows the configuration in bootstrap.properties:

    # The first extension configuration. The class identity is ext-config-01, the file format is properties, and refresh is supported.
    spring.cloud.sofa.config.extension-configs[0].data-id=ext-config-01
    spring.cloud.sofa.config.extension-configs[0].refresh=true
    # The second extension configuration. The class identity is ext-config-02.yml, the file format is yml, and refresh is not supported.
    spring.cloud.sofa.config.extension-configs[1].data-id=ext-config-02.yml
    • You can set multiple extension configurations. You can specify the configuration file type by appending a file extension, such as .yml, to the dataId property. The default type is properties. By default, extension configurations do not support refresh. You must enable it using the `refresh` property.

      Note

      A `dataId` with a specified file type is a complete class identity.

    • When you configure multiple `dataId`s, their priority is determined by the index `n`. The larger the value of n in spring.cloud.sofa.config.extension-configs[n].data-id, the higher the priority.

  • Spring Cloud SOFA DRM also supports shared configurations. This feature lets you use the same set of configurations across multiple applications. The following example shows the configuration in bootstrap.properties:

    # The first shared configuration. The class identity is share-config-01, the application is rpc, the file format is properties, and refresh is supported.
    spring.cloud.sofa.config.shared-configs[0].data-id=share-config-01
    spring.cloud.sofa.config.shared-configs[0].group=rpc
    spring.cloud.sofa.config.shared-configs[0].refresh=true
    # The second shared configuration. The class identity is share-config-02.yml, the application is share, the file format is yml, and refresh is not supported.
    spring.cloud.sofa.config.shared-configs[1].data-id=share-config-02.yml
    • The configuration rules for shared configurations are almost the same as for extension configurations, except that the key is different. The priority rules are also the same.

    • The application name for a shared configuration is configurable. You can use spring.cloud.sofa.config.shared-configs[n].group to set it. The default value is "share". Because this configuration is shared across multiple applications, you cannot specify a particular application name. Instead, the group name identifies the scope of the configuration.

    • A shared configuration acts as a global configuration template for a feature. It can be overwritten by extension configurations and application configurations. When all three types of configurations are used, the priority is as follows: shared configuration < extension configuration < application configuration.

Config Data mode

The implementation of Config Data mode differs from Bootstrap mode. Therefore, configurations designed for Bootstrap mode do not apply to Config Data mode. The Quick Start document provides a basic example of Config Data mode configuration. The following is a more complete example:

spring:
  application:
    name: {your-project-name}
  config:
    import: 
    - "drm:share-config-01.properties?group=rpc&refreshEnabled=true"
    - "drm:ext-config-01.yml"
    - "drm:"
    - "optional:drm:application1.properties"
  • In Config Data mode, you must use the spring.config.import property to set configurations. You can set multiple configurations. The priority is determined by the order in which they are listed, with the last configuration having the highest priority. Unlike in Bootstrap mode, you cannot use different configuration types to set priority. Therefore, you must arrange the configurations based on your priority requirements. Because all configuration information must be in a single string, the parameters use a URL-like format: drm:{class-identity}.{config-format}?k1=v1&k2=v2.

    The configuration format is optional. The default is `properties`.

  • The settings for connectTimeout, timeout, and refreshEnabled are the same as in Bootstrap mode. However, you configure them directly in the application.properties file instead of the bootstrap.properties file.

Program with native DRM annotations

In addition to the Spring Cloud programming interface, Spring Cloud SOFA DRM also supports programming with native DRM annotations. The usage is identical to SOFABoot. For more information, see Dynamic Configuration Quick Start.

Completely disable configuration

You can set spring.cloud.sofa.config.enabled = false in the application.properties file to completely disable the dynamic configuration feature of Spring Cloud SOFA DRM.

spring.cloud.sofa.config.enabled=false

Complete configuration reference

The Spring Cloud SOFA DRM module provides the following configuration items:

Configuration name

Description

Default value

spring.cloud.sofa.config.name

The configuration name.

application

spring.cloud.sofa.config.file-extension

The configuration type.

properties

spring.cloud.sofa.config.connect-timeout

The connection timeout for the server, in milliseconds. This sets the maximum wait time for the initial configuration pull.

3000 (milliseconds)

spring.cloud.sofa.config.timeout

The read timeout for the server, in milliseconds. This sets the maximum wait time for the initial configuration pull.

3000 (milliseconds)

spring.cloud.sofa.config.refresh-enabled

Specifies whether to allow dynamic refresh. If this is disabled, the configuration is pulled only once at startup and cannot be dynamically updated at runtime.

true

spring.cloud.sofa.config.shared-configs

Shared configurations. For more information, see Bootstrap mode.

None

spring.cloud.sofa.config.extension-configs

Extension configurations. For more information, see Bootstrap mode.

None

spring.cloud.sofa.config.enabled

The global switch.

true

spring.cloud.sofa.config.import-check.enabled

This is effective only in Config Data mode. By default, after you import the DRM module, an exception is thrown if you do not import a DRM configuration. Disable this setting to allow not importing DRM dynamic configurations.

true