Nacos Discovery Starter Configurations
The following shows the other configurations of the starter of Nacos Discovery:
Configuration |
Key |
Default Value |
Description |
Server address |
|
IP and port of the Nacos Server listener |
|
Service name |
|
|
Name the current service |
Weight |
|
|
Value range: 1 to 100. The bigger the value, the greater the weight |
Network card name |
|
If the IP address is not specified, the registered IP address is the IP address of the network card. If this is not specified either, the IP address of the first network card will be used by default. |
|
Registered IP address |
|
Highest priority |
|
Registered port |
|
|
Will be detected automatically by default. Do not need to be configured. |
Namespace |
|
A typical scenario is to isolate the service registration for different environment, such as resource (configurations, services etc.) isolation between testing and production environment |
|
AccessKey |
|
Alibaba Cloud account accesskey |
|
SecretKey |
|
Alibaba Cloud account secretkey |
|
Metadata |
|
You can define some of the metadata for your services in the Map format |
|
Log file name |
|
||
Cluster Name |
|
|
Cluster name of Nacos |
Endpoint |
|
The domain name of a certain service in a specific region. You can retrieve the server address dynamically with this domain name |
|
Integrate Ribbon or not |
|
|
Set to true in most cases |
Enable Nacos Watch |
|
|
set to false to close watch |
NacosDiscoveryProperties
@ConfigurationProperties("spring.cloud.nacos.discovery")
public class NacosDiscoveryProperties {
}
处理ip逻辑
@PostConstruct
public void init() throws SocketException {
metadata.put(PreservedMetadataKeys.REGISTER_SOURCE, "SPRING_CLOUD");
if (secure) {
metadata.put("secure", "true");
}
serverAddr = Objects.toString(serverAddr, "");
if (serverAddr.endsWith("/")) {
serverAddr = serverAddr.substring(0, serverAddr.length() - 1);
}
endpoint = Objects.toString(endpoint, "");
namespace = Objects.toString(namespace, "");
logName = Objects.toString(logName, "");
if (StringUtils.isEmpty(ip)) {
// traversing network interfaces if didn't specify a interface
if (StringUtils.isEmpty(networkInterface)) {
ip = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
}
else {
NetworkInterface netInterface = NetworkInterface
.getByName(networkInterface);
if (null == netInterface) {
throw new IllegalArgumentException(
"no such interface " + networkInterface);
}
Enumeration<InetAddress> inetAddress = netInterface.getInetAddresses();
while (inetAddress.hasMoreElements()) {
InetAddress currentAddress = inetAddress.nextElement();
if (currentAddress instanceof Inet4Address
&& !currentAddress.isLoopbackAddress()) {
ip = currentAddress.getHostAddress();
break;
}
}
if (StringUtils.isEmpty(ip)) {
throw new RuntimeException("cannot find available ip from"
+ " network interface " + networkInterface);
}
}
}
this.overrideFromEnv(environment);
}
上一篇: nginx yii2 配置
推荐阅读
-
创建一个spring alibaba nacos Discovery 服务注册demo
-
Nepxion Discovery学习笔记1 Nacos+Feign
-
Spring-Cloud-Alibaba-Nacos-Discovery 安装使用
-
Nacos--在Spring cloud中使用Spring Cloud Alibaba Nacos Discovery(Spring Cloud回顾)
-
Nacos--在Spring cloud中使用Spring Cloud Alibaba Nacos Discovery(服务注册+配置管理示例)
-
Spring Cloud Alibaba(1) 实现服务注册与发现 Nacos Discovery
-
记录使用spring-cloud-starter-alibaba-nacos-config 注册到 nacos 时配置问题。
-
Nacos Discovery Starter Configurations
-
Java Spring Cloud Alibaba-Nacos 注册中心:(六)Nacos Discovery 对外暴露的 Endpoint