Spring Cloud Alibaba Tutorials | Nacos (d)

Nacos environmental isolation

Nacos management station has a separate menu "namespace", which there is a default "public" is the default namespace called, whether we as a registration center or distribution center, are in effect when using Nacos under the namespace , then the namespace in the end what role it plays? In fact, Nacos logic based Namespace to help users isolate multiple namespaces, which can help users better manage the testing, pre-development, production and other environmental services and configuration, so that the same configuration of each environment (such as a database data source) can be defined different values.

Here Insert Picture Description
We understand that the namespace is to play a role in the emergence of environmental isolation, in fact, not only is the namespace, group and Data Id environment can also play the role of isolation. Data Id values:. $ {Spring.cloud.nacos.config.prefix} - $ {spring.profile.active} $ {spring.cloud.nacos.config.file-extension}, and is spring.profiles.active We can distinguish between different environments. So how rational use namespace, group and Data Id to distinguish between different environments, it is a question we have to consider carefully when using Nacos.
Here Insert Picture Description

Classic Case

Nacos is written in Alibaba engineer, is used in large-scale projects which platform, so they stand on the issue of perspective will enable us to better understand the environment they are designed isolation purposes. Suppose we now need to do a large platform project, a large platform project will provide support services for individual enterprises, but different companies there are different subprojects and each subproject needs to have multiple configuration environment, as follows:
Here Insert Picture Description
Faced with this demand when the rational use of Nacos environmental isolation strategy is more enough to let us save a lot of time cost.

  • For different enterprises this layer we can use the namespace to distinguish.
  • For businesses, we can use the following different sub-projects group distinguished.
  • Different for each sub-project environment we can use Data Id make that distinction.

According to the above environmental isolation strategies, test environment configuration if we need to add a B B business following subprojects nacos-provider module, it can be configured:

The first step : add a namespace B enterprises.
Here Insert Picture Description
Step two : Add Profile configuration list, group on behalf of the project, Data Id modules as well as representatives of different operating environments.
Here Insert Picture Description
Here Insert Picture Description
The third step : modifying nacos-provider module specified namespace, group and active.
Here Insert Picture Description
Step Four : Run nacos-provider module verification result.
Here Insert Picture Description
Here Insert Picture Description

Step five : Use the startup parameter specifies the environment. Although this environment to achieve the isolation, but are hard-coded way, as we wrote in bootstrap.yml died of environmental parameters, the actual development should be used to start arguments.

-Dspring.cloud.nacos.config.namespace=bb9f6e91-3455-4020-903f-6a2726284e62
-Dspring.cloud.nacos.config.group=project_B
-Dspring.profiles.active=TEST

Here Insert Picture Description

No public attention for more original Bowen

Alt

Guess you like

Origin www.cnblogs.com/engineer-luke/p/12171105.html