Apollo's core concept of "Namespace"

4092 단어 Configuration Center

1. What is a namespace?


Namespace is a collection of configuration items, similar to the concept of a configuration file.

2. What is the "application" namespace?


When Apollo creates a project, it will create an "application"Namespace by default. As the name suggests, "application"is used by the application itself. Students who are familiar with Spring Boot know that Spring Boot projects have a default configuration file application.yml. Here application.yml is equivalent to the "application"Namespace. For 90% of applications, the namespace of "application"already meets the daily configuration usage scenarios.
The code for the client to obtain the "application"Namespace is as follows:
  Config config = ConfigService.getAppConfig();
The code for the client to obtain the non-"application"Namespace is as follows:
  Config config = ConfigService.getConfig(namespaceName);

3. What are the formats of Namespace?


Configuration files come in various formats, such as: properties, xml, yml, yaml, json, etc. The same Namespace also has these formats. In the Portal UI, you can see that there is a "properties"label on the Namespace of "application", indicating that "application"is in properties format.

Note: The namespace in non-properties format needs to be obtained by calling ConfigService.getConfigFile(String namespace, ConfigFileFormat configFileFormat) when the client uses it. If it is called directly using the Http interface, the corresponding namespace parameter needs to be passed in the name of the namespace plus the suffix name, such as datasources.json.

4. Classification of access permissions for Namespace


There are two types of access permissions for Namespace:

  • private
  • public

  • The access permissions here are relative to the Apollo client.
    4.1 Private permissions
    Namespace with private permission can only be obtained by the application to which it belongs. When an application tries to obtain the private Namespace of another application, Apollo will report a "404"exception.
    4.2 Public permission
    Namespace of public permission, which can be obtained by any application.

    5. Types of Namespaces


    There are three types of Namespace:

  • Private Type
  • public type
  • Associated types (inherited types)

  • 5.1 Private Types
    Namespaces of private types have private permissions. For example, the "application"namespace mentioned above is a private type.
    5.2 Public Types
    5.2.1 Meaning
    Namespaces of public types have public permissions. The public namespace is equivalent to a configuration outside the application, and the public namespace is identified by the name of the namespace, so the name of the public namespace must be globally unique.
    5.2.2 Usage scenarios

  • Configuration for department level sharing
  • Group level shared configuration
  • Configuration shared between several projects
  • Middleware client configuration

  • 5.3 Association Types
    5.3.1 Meaning
    Associated types can also be called inheritance types, and associated types have private permissions. The Namespace of the associated type inherits from the Namespace of the public type and is used to override some configurations of the public Namespace. For example, the public Namespace has two configuration items
    k1 = v1
    k2 = v2
    
    Then application A has an associated type of Namespace associated with this public Namespace, and overwrites the configuration item k1, and the new value is v3. Then when application A actually runs, the configuration of the obtained public namespace is:
    k1 = v3
    k2 = v2
    

    좋은 웹페이지 즐겨찾기