mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
服务注册切换
This commit is contained in:
parent
28c9e630cb
commit
1a163b1b85
@ -64,8 +64,8 @@ import static com.alibaba.nacos.api.PropertyKeyConst.USERNAME;
|
||||
* @author xiaojing
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
* @author <a href="mailto:lyuzb@lyuzb.com">lyuzb</a>
|
||||
* @author <a href="mailto:78552423@qq.com">eshun</a>
|
||||
*/
|
||||
|
||||
@ConfigurationProperties("spring.cloud.nacos.discovery")
|
||||
public class NacosDiscoveryProperties {
|
||||
|
||||
@ -211,6 +211,7 @@ public class NacosDiscoveryProperties {
|
||||
|
||||
@PostConstruct
|
||||
public void init() throws SocketException {
|
||||
namingService = null;
|
||||
|
||||
metadata.put(PreservedMetadataKeys.REGISTER_SOURCE, "SPRING_CLOUD");
|
||||
if (secure) {
|
||||
|
@ -33,6 +33,7 @@ import static org.springframework.util.ReflectionUtils.rethrowRuntimeException;
|
||||
/**
|
||||
* @author xiaojing
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
* @author <a href="mailto:78552423@qq.com">eshun</a>
|
||||
*/
|
||||
public class NacosServiceRegistry implements ServiceRegistry<Registration> {
|
||||
|
||||
@ -40,11 +41,8 @@ public class NacosServiceRegistry implements ServiceRegistry<Registration> {
|
||||
|
||||
private final NacosDiscoveryProperties nacosDiscoveryProperties;
|
||||
|
||||
private final NamingService namingService;
|
||||
|
||||
public NacosServiceRegistry(NacosDiscoveryProperties nacosDiscoveryProperties) {
|
||||
this.nacosDiscoveryProperties = nacosDiscoveryProperties;
|
||||
this.namingService = nacosDiscoveryProperties.namingServiceInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -55,6 +53,7 @@ public class NacosServiceRegistry implements ServiceRegistry<Registration> {
|
||||
return;
|
||||
}
|
||||
|
||||
NamingService namingService = namingService();
|
||||
String serviceId = registration.getServiceId();
|
||||
String group = nacosDiscoveryProperties.getGroup();
|
||||
|
||||
@ -84,7 +83,7 @@ public class NacosServiceRegistry implements ServiceRegistry<Registration> {
|
||||
return;
|
||||
}
|
||||
|
||||
NamingService namingService = nacosDiscoveryProperties.namingServiceInstance();
|
||||
NamingService namingService = namingService();
|
||||
String serviceId = registration.getServiceId();
|
||||
String group = nacosDiscoveryProperties.getGroup();
|
||||
|
||||
@ -165,4 +164,8 @@ public class NacosServiceRegistry implements ServiceRegistry<Registration> {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private NamingService namingService() {
|
||||
return nacosDiscoveryProperties.namingServiceInstance();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user