Polish : spring-cloud-incubator/spring-cloud-alibaba#377 : rename the metadata properties
@@ -18,6 +18,7 @@ package org.springframework.cloud.alibaba.nacos.discovery;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.ListView;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.alibaba.nacos.NacosDiscoveryProperties;
@@ -25,7 +26,11 @@ import org.springframework.cloud.alibaba.nacos.NacosServiceInstance;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
/**
* @author xiaojing
@@ -54,8 +59,7 @@ public class NacosDiscoveryClient implements DiscoveryClient {
List<Instance> instances = discoveryProperties.namingServiceInstance()
.selectInstances(serviceId, true);
return hostToServiceInstanceList(instances, serviceId);
- }
- catch (Exception e) {
+ } catch (Exception e) {
throw new RuntimeException(
"Can not get hosts from nacos server. serviceId: " + serviceId, e);
}
@@ -67,11 +71,12 @@ public class NacosDiscoveryClient implements DiscoveryClient {
nacosServiceInstance.setHost(instance.getIp());
nacosServiceInstance.setPort(instance.getPort());
nacosServiceInstance.setServiceId(serviceId);
+
Map<String, String> metadata = new HashMap<>();
- metadata.put("instanceId", instance.getInstanceId());
- metadata.put("weight", instance.getWeight() + "");
- metadata.put("healthy", instance.isHealthy() + "");
- metadata.put("cluster", instance.getClusterName() + "");
+ metadata.put("nacos.instanceId", instance.getInstanceId());
+ metadata.put("nacos.weight", instance.getWeight() + "");
+ metadata.put("nacos.healthy", instance.isHealthy() + "");
+ metadata.put("nacos.cluster", instance.getClusterName() + "");
metadata.putAll(instance.getMetadata());
nacosServiceInstance.setMetadata(metadata);
@@ -98,8 +103,7 @@ public class NacosDiscoveryClient implements DiscoveryClient {
ListView<String> services = discoveryProperties.namingServiceInstance()
.getServicesOfServer(1, Integer.MAX_VALUE);
return services.getData();
- }
- catch (Exception e) {
+ } catch (Exception e) {
log.error("get service name from nacos server fail,", e);
return Collections.emptyList();
}
