当前位置:网站首页>[microservice] Nacos cluster building and loading file configuration
[microservice] Nacos cluster building and loading file configuration
2022-07-04 05:41:00 【Classmate Tao Ran】

Here is 【 Microservices 】, Pay attention to me to learn micro services without getting lost
If it helps you , Give the blogger a free praise to show encouragement
You are welcome to comment on the collection ️
Column introduction
【 Microservices 】 At present, it mainly updates micro services , Learn together and progress together .
Introduction to this issue
This issue focuses on Nacos Cluster setup and loading file configuration
List of articles
Catalog
nacos To configure DataId Introduce
To configure yml In the document DataId
To configure console Medium DataId
Multi environment configuration
Service cluster
demand
Service providers build clusters
Service caller , Display the information of each service in the cluster in turn


build
1) Modify service provider's controller, Print the server port number

package com.czxy.controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
@RestController
public class EchoController {
@Resource
private HttpServletRequest request;
@RequestMapping(value = "/echo/{string}", method = RequestMethod.GET)
public String echo(@PathVariable String string) {
int serverPort = request.getServerPort();
return "Hello Nacos Discovery " + string + ":" + serverPort;
}
}
2) To write yml To configure

# Port number
server:
port: 8170
spring:
application:
name: service-provider # service name
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848 #nacos Service address
# Port number
server:
port: 8270
spring:
application:
name: service-provider # service name
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848 #nacos Service address
3) To configure idea Start item
-Dspring.profiles.active=8170

test
start-up 3 A service (2 Service offerings ,1 Service consumption )

- see nacos Console

Load profile order
Yes
3.4.5 chapter / The first 4 StepExplain the content in detailThe order in which the configuration files are loaded ( The first 4 Step by step )
nacos To configure DataId Introduce
nacos Provides 3 Ways of planting , To configure dataId Loading order of
A: Shared configuration :
spring.cloud.nacos.config.shared-dataids
spring.cloud.nacos.config.refreshable-dataidsB: Load multiple configurations :
spring.cloud.nacos.config.ext-config[n]C: Internal rule splicing :
spring.cloud.nacos.config.prefix
spring.cloud.nacos.config.file-extension
spring.cloud.nacos.config.group
To configure yml In the document DataId
spring:
application:
name: config-service # service name
cloud:
nacos:
config:
server-addr: 127.0.0.1:8848 # nacos Service address
shared-dataids: test1.yml # 1.1 Shared configuration
refreshable-dataids: test1.yml # 1.2 Shared configuration , Dynamic refresh
ext-config: # 2. Configure multiple
- data-id: test2-1.yml
group: DEFAULT_GROUP
refresh: true
- data-id: test2-2.yml
group: DEFAULT_GROUP
refresh: true
prefix: test3 # 3.1 Prefix , Default ${spring.application.name}
file-extension: yaml # 3.2 suffix
group: DEFAULT_GROUP # 3.3 Group name To configure console Medium DataId
nacos Console configuration

test
Loaded later dataId Will overwrite the previously loaded dataId What to set up
Check the log

Located property source: [
BootstrapPropertySource {name='bootstrapProperties-test3-demo.yaml'}, BootstrapPropertySource {name='bootstrapProperties-test3.yaml'}, BootstrapPropertySource {name='bootstrapProperties-test2-2.yml'}, BootstrapPropertySource {name='bootstrapProperties-test2-1.yml'}, BootstrapPropertySource {name='bootstrapProperties-test1.yml'}]
Multi environment configuration
stay Nacos For different environments ( Development 、 test 、 Production etc. ) in , It provides several concepts at different levels of management , Include :
Data ID、Group、Namespace.
| Concept | describe |
|---|---|
| Data ID | Unique identification of data , Can be understood as Spring Cloud The profile name of the application |
| Group | Used to correct Data ID Do collection management , Equivalent to small classification |
| Namespace | Used for tenant granularity configuration isolation . Equivalent to a large classification |
- Group group To configure
spring.cloud.nacos.config.group= # Group name
- Namespace namespace To configure
spring.cloud.nacos.config.namespace= #namespace Of ID
边栏推荐
- Signification des lettres du module optique et abréviation des paramètres Daquan
- FreeRTOS 中 RISC-V-Qemu-virt_GCC 的 锁机制 分析
- Kubernets first meeting
- Yyds dry goods inventory TCP & UDP
- 简易零钱通
- JS string splicing enhancement
- 卸载Google Drive 硬盘-必须退出程序才能卸载
- C language simple student management system (including source code)
- ANSYS command
- Leetcode 184 Employees with the highest wages in the Department (July 3, 2022)
猜你喜欢
![BUU-Real-[PHP]XXE](/img/97/b7139270145e6aa6a4f5d1067e2527.jpg)
BUU-Real-[PHP]XXE

PostgreSQL has officially surpassed mysql. Is this guy too strong!

云原生架构实战案例及优化解决方案

拓扑排序和关键路径的图形化显示
![How to use postman to realize simple interface Association [add, delete, modify and query]](/img/e9/bf89eacdebcf2ec84c8a08c28b9ca8.png)
How to use postman to realize simple interface Association [add, delete, modify and query]

Penetration tool - sqlmap

Just do it with your hands 7 - * project construction details 2 - hook configuration

LM small programmable controller software (based on CoDeSys) note 22: error 4268/4052

卸载Google Drive 硬盘-必须退出程序才能卸载

LabVIEW错误对话框的出现
随机推荐
LM small programmable controller software (based on CoDeSys) note XXI: error 3703
BUU-Crypto-[HDCTF2019]basic rsa
Design and implementation of tcp/ip series overview
Just do it with your hands 7 - * project construction details 2 - hook configuration
Talk about the SQL server version of DTM sub transaction barrier function
How to use postman to realize simple interface Association [add, delete, modify and query]
Input displays the currently selected picture
VB.net GIF(制作、拆解——优化代码,类库——5)
2022 R2 mobile pressure vessel filling retraining question bank and answers
Actual cases and optimization solutions of cloud native architecture
Leetcode 184 Employees with the highest wages in the Department (July 3, 2022)
left_and_right_net正常版本
VB. Net GIF (making and disassembling - optimizing code, class library - 5)
c语言经典指针和数组笔试题解析
Letter meaning and parameter abbreviation of optical module Daquan
LM小型可编程控制器软件(基于CoDeSys)笔记二十二:错误4268/4052
Luogu deep foundation part 1 Introduction to language Chapter 5 array and data batch storage
LabVIEW错误对话框的出现
BUU-Crypto-[GUET-CTF2019]BabyRSA
Risc-v-qemu-virt in FreeRTOS_ Lock mechanism analysis of GCC