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 |
group | spring.cloud.nacos.discovery.group |
customize group |
@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);
}