当前位置:网站首页>【微服务】Nacos集群搭建以及加载文件配置
【微服务】Nacos集群搭建以及加载文件配置
2022-07-28 22:17:00 【鹅鹅鹅呢】
??这里是【微服务】,关注我学习微服务不迷路
??如果对你有帮助,给博主一个免费的点赞以示鼓励
欢迎各位??点赞??评论收藏
??专栏介绍
【微服务】 目前主要更新微服务,一起学习一起进步。
??本期介绍
本期主要介绍Nacos集群搭建以及加载文件配置
文章目录
目录
服务集群
需求
服务提供者搭建集群
服务调用者,依次显示集群中各服务的信息
搭建
1)修改服务提供方的controller,打印服务端端口号
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)编写yml配置
#端口号
server:
port: 8170
spring:
application:
name: service-provider #服务名
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848 #nacos服务地址
#端口号
server:
port: 8270
spring:
application:
name: service-provider #服务名
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848 #nacos服务地址
3)配置idea启动项
-Dspring.profiles.active=8170
测试
- 启动3个服务(2个服务提供,1个服务消费)
- 查看nacos控制台
加载配置文件顺序
对
3.4.5章节/第4步
内容进行详解加载配置文件的顺序(第4步详解)
nacos配置DataId介绍
- nacos 提供了3种方式,配置dataId的加载顺序
A: 共享配置:
spring.cloud.nacos.config.shared-dataids
spring.cloud.nacos.config.refreshable-dataids
B: 加载多配置:
spring.cloud.nacos.config.ext-config[n]
C: 内部规则拼接:
spring.cloud.nacos.config.prefix
spring.cloud.nacos.config.file-extension
spring.cloud.nacos.config.group
配置yml文件中的DataId
spring:
application:
name: config-service # 服务名
cloud:
nacos:
config:
server-addr: 127.0.0.1:8848 # nacos 服务地址
shared-dataids: test1.yml # 1.1 共享配置
refreshable-dataids: test1.yml # 1.2 共享配置,动态刷新
ext-config: # 2. 配置多个
- data-id: test2-1.yml
group: DEFAULT_GROUP
refresh: true
- data-id: test2-2.yml
group: DEFAULT_GROUP
refresh: true
prefix: test3 # 3.1 前缀,默认 ${spring.application.name}
file-extension: yaml # 3.2 后缀
group: DEFAULT_GROUP # 3.3 组名
配置console中的DataId
- nacos控制台配置
测试
后面加载的dataId将覆盖前面加载的dataId设置的内容
查看日志
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'}]
多环境配置
- 在Nacos为不同的环境(开发、测试、生产等)中,提供了多个不同管理级别的概念,包括:
Data ID
、Group
、Namespace
。
概念
描述
Data ID
数据唯一标识,可理解为Spring Cloud应用的配置文件名
Group
用来对Data ID
做集合管理,相当于小分类
Namespace
用于进行租户粒度的配置隔离。相当于大分类
- 组group配置
spring.cloud.nacos.config.group= #组名称
- 命名空间 namespace配置
spring.cloud.nacos.config.namespace= #namespace的ID
边栏推荐
- 迅为IMX6开发板QT系统创建AP热点基于RTL8723-交叉编译iptables
- SAP 临时表空间错误处理
- SAP oracle 复制新实例后数据库远程连接报错 ora-01031
- [data mining engineer - written examination] Dahua shares in 2022
- Powercl batch creates and manages virtual switches
- Multisensor fusion positioning (III) -- inertial technology
- RHCE first day
- 【详细超简单】如何使用WebSocket链接
- OpenCV宏定义
- 实时数仓:网易严选基于Flink的实时数仓实践
猜你喜欢
CANoe应用案例之DoIP通信
DoIP测试开发实践
脲酶丨Worthington杰克豆脲酶的特性及测定方案
Multisensor fusion positioning (III) -- inertial technology
Worthington - chemical properties and related studies of Worthington trypsin
Powercli VMware vCenter deploys conventional new VMS in batch through self built PXE server with one click
Uricase - Characteristics of uricase in Worthington pig liver:
【C】atoi和offsetof的介绍和模拟实现
The failure rate is as high as 80%. How to correctly complete the strategic planning of digital transformation?
RHCE first day
随机推荐
电商数据模型设计
【TA-霜狼_may-《百人计划》】图形3.6 纹理压缩——包体瘦身术
剑指 Offer 55 - I. 二叉树的深度
1-8 props的基础使用
VS2005 accesses the setting method "recommended collection" of vss2005 through sourceoffsite
EN 1873 assembly accessories for roofing - plastic single roof lamps - CE certification
Exchange 2013 SSL证书安装文档
leetcode 763. Partition Labels 划分字母区间(中等)
Uricase - Characteristics of uricase in Worthington pig liver:
CANoe应用案例之DoIP通信
C language n*n matrix evaluation and inverse matrix [easy to understand]
【MySQL 8】Generated Invisible Primary Keys(GIPK)
Leetcode64. 最小路径和
Hyperparametric optimization (grid search and Bayesian Optimization)
After SAP Oracle replicates a new instance, the remote connection of the database reports an error ora-01031
多传感器融合定位(一)——3D激光里程计
Worthington核糖核酸酶B历史和化学性质说明
Jincang database kingbasees client programming interface guide ODBC (5. Development process)
[data mining engineer - written examination] Dahua shares in 2022
SAP 临时表空间错误处理