mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
commit
2a643c82bf
@ -23,6 +23,11 @@
|
|||||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-alibaba-sentinel-datasource</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
@ -36,10 +41,10 @@
|
|||||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!--<dependency>-->
|
<dependency>
|
||||||
<!--<groupId>com.alibaba.csp</groupId>-->
|
<groupId>com.alibaba.csp</groupId>
|
||||||
<!--<artifactId>sentinel-datasource-nacos</artifactId>-->
|
<artifactId>sentinel-datasource-nacos</artifactId>
|
||||||
<!--</dependency>-->
|
</dependency>
|
||||||
<!--<dependency>-->
|
<!--<dependency>-->
|
||||||
<!--<groupId>com.alibaba.csp</groupId>-->
|
<!--<groupId>com.alibaba.csp</groupId>-->
|
||||||
<!--<artifactId>sentinel-datasource-zookeeper</artifactId>-->
|
<!--<artifactId>sentinel-datasource-zookeeper</artifactId>-->
|
||||||
|
@ -15,6 +15,13 @@ spring.cloud.sentinel.web-context-unify=true
|
|||||||
#spring.cloud.sentinel.filter.enabled=false
|
#spring.cloud.sentinel.filter.enabled=false
|
||||||
#spring.cloud.sentinel.http-method-specify=false
|
#spring.cloud.sentinel.http-method-specify=false
|
||||||
|
|
||||||
|
#spring.cloud.sentinel.datasource.ds6.nacos.server-addr=127.0.0.1:8848
|
||||||
|
#spring.cloud.sentinel.datasource.ds6.nacos.username=nacos
|
||||||
|
#spring.cloud.sentinel.datasource.ds6.nacos.password=nacos
|
||||||
|
#spring.cloud.sentinel.datasource.ds6.nacos.dataId=flowrule.json
|
||||||
|
#spring.cloud.sentinel.datasource.ds6.nacos.data-type=json
|
||||||
|
#spring.cloud.sentinel.datasource.ds6.nacos.rule-type=flow
|
||||||
|
|
||||||
spring.cloud.sentinel.datasource.ds1.file.file=classpath: flowrule.json
|
spring.cloud.sentinel.datasource.ds1.file.file=classpath: flowrule.json
|
||||||
spring.cloud.sentinel.datasource.ds1.file.data-type=json
|
spring.cloud.sentinel.datasource.ds1.file.data-type=json
|
||||||
spring.cloud.sentinel.datasource.ds1.file.rule-type=flow
|
spring.cloud.sentinel.datasource.ds1.file.rule-type=flow
|
||||||
|
@ -20,9 +20,10 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-cloud-starter-gateway</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -33,10 +34,6 @@
|
|||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>io.projectreactor</groupId>
|
|
||||||
<artifactId>reactor-core</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
@ -6,11 +6,13 @@ spring:
|
|||||||
username: nacos
|
username: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
discovery:
|
discovery:
|
||||||
server-addr: localhost:8848
|
server-addr: 127.0.0.1:8848
|
||||||
|
group: test
|
||||||
gateway:
|
gateway:
|
||||||
discovery:
|
discovery:
|
||||||
locator:
|
locator:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
||||||
application:
|
application:
|
||||||
name: node-service
|
name: node-service
|
||||||
sidecar:
|
sidecar:
|
||||||
@ -18,6 +20,7 @@ sidecar:
|
|||||||
ip: 127.0.0.1
|
ip: 127.0.0.1
|
||||||
# 异构微服务的端口
|
# 异构微服务的端口
|
||||||
port: 8060
|
port: 8060
|
||||||
|
|
||||||
# 异构微服务的健康检查URL
|
# 异构微服务的健康检查URL
|
||||||
#health-check-url: http://localhost:8060/health.json
|
#health-check-url: http://localhost:8060/health.json
|
||||||
management:
|
management:
|
||||||
|
@ -32,6 +32,10 @@ public class NacosDataSourceProperties extends AbstractDataSourceProperties {
|
|||||||
|
|
||||||
private String serverAddr;
|
private String serverAddr;
|
||||||
|
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
private String password;
|
||||||
|
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
private String groupId = "DEFAULT_GROUP";
|
private String groupId = "DEFAULT_GROUP";
|
||||||
|
|
||||||
@ -67,6 +71,22 @@ public class NacosDataSourceProperties extends AbstractDataSourceProperties {
|
|||||||
this.serverAddr = serverAddr;
|
this.serverAddr = serverAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
public String getGroupId() {
|
public String getGroupId() {
|
||||||
return groupId;
|
return groupId;
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,10 @@ public class NacosDataSourceFactoryBean implements FactoryBean<NacosDataSource>
|
|||||||
|
|
||||||
private String serverAddr;
|
private String serverAddr;
|
||||||
|
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
private String password;
|
||||||
|
|
||||||
private String groupId;
|
private String groupId;
|
||||||
|
|
||||||
private String dataId;
|
private String dataId;
|
||||||
@ -63,6 +67,8 @@ public class NacosDataSourceFactoryBean implements FactoryBean<NacosDataSource>
|
|||||||
if (!StringUtils.isEmpty(this.namespace)) {
|
if (!StringUtils.isEmpty(this.namespace)) {
|
||||||
properties.setProperty(PropertyKeyConst.NAMESPACE, this.namespace);
|
properties.setProperty(PropertyKeyConst.NAMESPACE, this.namespace);
|
||||||
}
|
}
|
||||||
|
properties.setProperty(PropertyKeyConst.USERNAME, this.username);
|
||||||
|
properties.setProperty(PropertyKeyConst.PASSWORD, this.password);
|
||||||
return new NacosDataSource(properties, groupId, dataId, converter);
|
return new NacosDataSource(properties, groupId, dataId, converter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,6 +85,22 @@ public class NacosDataSourceFactoryBean implements FactoryBean<NacosDataSource>
|
|||||||
this.serverAddr = serverAddr;
|
this.serverAddr = serverAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
public String getGroupId() {
|
public String getGroupId() {
|
||||||
return groupId;
|
return groupId;
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,9 @@ public class NacosDataPropertiesParser extends AbstractNacosDataParser {
|
|||||||
log.warn("the config data is invalid {}", dataLine);
|
log.warn("the config data is invalid {}", dataLine);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
result.put(dataLine.substring(0, index), dataLine.substring(index + 1));
|
String key = dataLine.substring(0, index);
|
||||||
|
String value = dataLine.substring(index + 1);
|
||||||
|
result.put(key.trim(), value.trim());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -64,8 +64,8 @@ import static com.alibaba.nacos.api.PropertyKeyConst.USERNAME;
|
|||||||
* @author xiaojing
|
* @author xiaojing
|
||||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||||
* @author <a href="mailto:lyuzb@lyuzb.com">lyuzb</a>
|
* @author <a href="mailto:lyuzb@lyuzb.com">lyuzb</a>
|
||||||
|
* @author <a href="mailto:78552423@qq.com">eshun</a>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ConfigurationProperties("spring.cloud.nacos.discovery")
|
@ConfigurationProperties("spring.cloud.nacos.discovery")
|
||||||
public class NacosDiscoveryProperties {
|
public class NacosDiscoveryProperties {
|
||||||
|
|
||||||
@ -211,6 +211,7 @@ public class NacosDiscoveryProperties {
|
|||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() throws SocketException {
|
public void init() throws SocketException {
|
||||||
|
namingService = null;
|
||||||
|
|
||||||
metadata.put(PreservedMetadataKeys.REGISTER_SOURCE, "SPRING_CLOUD");
|
metadata.put(PreservedMetadataKeys.REGISTER_SOURCE, "SPRING_CLOUD");
|
||||||
if (secure) {
|
if (secure) {
|
||||||
|
@ -33,6 +33,7 @@ import static org.springframework.util.ReflectionUtils.rethrowRuntimeException;
|
|||||||
/**
|
/**
|
||||||
* @author xiaojing
|
* @author xiaojing
|
||||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||||
|
* @author <a href="mailto:78552423@qq.com">eshun</a>
|
||||||
*/
|
*/
|
||||||
public class NacosServiceRegistry implements ServiceRegistry<Registration> {
|
public class NacosServiceRegistry implements ServiceRegistry<Registration> {
|
||||||
|
|
||||||
@ -40,11 +41,8 @@ public class NacosServiceRegistry implements ServiceRegistry<Registration> {
|
|||||||
|
|
||||||
private final NacosDiscoveryProperties nacosDiscoveryProperties;
|
private final NacosDiscoveryProperties nacosDiscoveryProperties;
|
||||||
|
|
||||||
private final NamingService namingService;
|
|
||||||
|
|
||||||
public NacosServiceRegistry(NacosDiscoveryProperties nacosDiscoveryProperties) {
|
public NacosServiceRegistry(NacosDiscoveryProperties nacosDiscoveryProperties) {
|
||||||
this.nacosDiscoveryProperties = nacosDiscoveryProperties;
|
this.nacosDiscoveryProperties = nacosDiscoveryProperties;
|
||||||
this.namingService = nacosDiscoveryProperties.namingServiceInstance();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -55,6 +53,7 @@ public class NacosServiceRegistry implements ServiceRegistry<Registration> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NamingService namingService = namingService();
|
||||||
String serviceId = registration.getServiceId();
|
String serviceId = registration.getServiceId();
|
||||||
String group = nacosDiscoveryProperties.getGroup();
|
String group = nacosDiscoveryProperties.getGroup();
|
||||||
|
|
||||||
@ -84,7 +83,7 @@ public class NacosServiceRegistry implements ServiceRegistry<Registration> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NamingService namingService = nacosDiscoveryProperties.namingServiceInstance();
|
NamingService namingService = namingService();
|
||||||
String serviceId = registration.getServiceId();
|
String serviceId = registration.getServiceId();
|
||||||
String group = nacosDiscoveryProperties.getGroup();
|
String group = nacosDiscoveryProperties.getGroup();
|
||||||
|
|
||||||
@ -165,4 +164,8 @@ public class NacosServiceRegistry implements ServiceRegistry<Registration> {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private NamingService namingService() {
|
||||||
|
return nacosDiscoveryProperties.namingServiceInstance();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ package com.alibaba.cloud.sidecar;
|
|||||||
|
|
||||||
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
|
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.core.env.ConfigurableEnvironment;
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
@ -28,7 +27,6 @@ import org.springframework.web.client.RestTemplate;
|
|||||||
* @author www.itmuch.com
|
* @author www.itmuch.com
|
||||||
*/
|
*/
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@EnableConfigurationProperties(SidecarProperties.class)
|
|
||||||
public class SidecarAutoConfiguration {
|
public class SidecarAutoConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
@ -17,12 +17,15 @@
|
|||||||
package com.alibaba.cloud.sidecar.nacos;
|
package com.alibaba.cloud.sidecar.nacos;
|
||||||
|
|
||||||
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
||||||
|
import com.alibaba.cloud.nacos.discovery.NacosDiscoveryAutoConfiguration;
|
||||||
import com.alibaba.cloud.sidecar.SidecarAutoConfiguration;
|
import com.alibaba.cloud.sidecar.SidecarAutoConfiguration;
|
||||||
import com.alibaba.cloud.sidecar.SidecarDiscoveryClient;
|
import com.alibaba.cloud.sidecar.SidecarDiscoveryClient;
|
||||||
|
import com.alibaba.cloud.sidecar.SidecarProperties;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
@ -30,15 +33,24 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
* @author www.itmuch.com
|
* @author www.itmuch.com
|
||||||
*/
|
*/
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@AutoConfigureBefore(SidecarAutoConfiguration.class)
|
@AutoConfigureBefore({ NacosDiscoveryAutoConfiguration.class,
|
||||||
@ConditionalOnBean(NacosDiscoveryProperties.class)
|
SidecarAutoConfiguration.class })
|
||||||
|
@ConditionalOnClass(NacosDiscoveryProperties.class)
|
||||||
|
@EnableConfigurationProperties(SidecarProperties.class)
|
||||||
public class SidecarNacosAutoConfiguration {
|
public class SidecarNacosAutoConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
public SidecarNacosDiscoveryProperties sidecarNacosDiscoveryProperties(
|
||||||
|
SidecarProperties sidecarProperties) {
|
||||||
|
return new SidecarNacosDiscoveryProperties(sidecarProperties);
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
public SidecarDiscoveryClient sidecarDiscoveryClient(
|
public SidecarDiscoveryClient sidecarDiscoveryClient(
|
||||||
NacosDiscoveryProperties nacosDiscoveryProperties) {
|
SidecarNacosDiscoveryProperties sidecarNacosDiscoveryProperties) {
|
||||||
return new SidecarNacosDiscoveryClient(nacosDiscoveryProperties);
|
return new SidecarNacosDiscoveryClient(sidecarNacosDiscoveryProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.alibaba.cloud.sidecar.nacos;
|
package com.alibaba.cloud.sidecar.nacos;
|
||||||
|
|
||||||
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
|
||||||
import com.alibaba.cloud.sidecar.SidecarDiscoveryClient;
|
import com.alibaba.cloud.sidecar.SidecarDiscoveryClient;
|
||||||
import com.alibaba.nacos.api.exception.NacosException;
|
import com.alibaba.nacos.api.exception.NacosException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -30,18 +29,19 @@ public class SidecarNacosDiscoveryClient implements SidecarDiscoveryClient {
|
|||||||
private static final Logger log = LoggerFactory
|
private static final Logger log = LoggerFactory
|
||||||
.getLogger(SidecarNacosDiscoveryClient.class);
|
.getLogger(SidecarNacosDiscoveryClient.class);
|
||||||
|
|
||||||
private final NacosDiscoveryProperties nacosDiscoveryProperties;
|
private final SidecarNacosDiscoveryProperties sidecarNacosDiscoveryProperties;
|
||||||
|
|
||||||
public SidecarNacosDiscoveryClient(
|
public SidecarNacosDiscoveryClient(
|
||||||
NacosDiscoveryProperties nacosDiscoveryProperties) {
|
SidecarNacosDiscoveryProperties sidecarNacosDiscoveryProperties) {
|
||||||
this.nacosDiscoveryProperties = nacosDiscoveryProperties;
|
this.sidecarNacosDiscoveryProperties = sidecarNacosDiscoveryProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerInstance(String applicationName, String ip, Integer port) {
|
public void registerInstance(String applicationName, String ip, Integer port) {
|
||||||
try {
|
try {
|
||||||
this.nacosDiscoveryProperties.namingServiceInstance().registerInstance(
|
this.sidecarNacosDiscoveryProperties.namingServiceInstance().registerInstance(
|
||||||
applicationName, nacosDiscoveryProperties.getGroup(), ip, port);
|
applicationName, sidecarNacosDiscoveryProperties.getGroup(), ip,
|
||||||
|
port);
|
||||||
}
|
}
|
||||||
catch (NacosException e) {
|
catch (NacosException e) {
|
||||||
log.warn("nacos exception happens", e);
|
log.warn("nacos exception happens", e);
|
||||||
@ -51,8 +51,9 @@ public class SidecarNacosDiscoveryClient implements SidecarDiscoveryClient {
|
|||||||
@Override
|
@Override
|
||||||
public void deregisterInstance(String applicationName, String ip, Integer port) {
|
public void deregisterInstance(String applicationName, String ip, Integer port) {
|
||||||
try {
|
try {
|
||||||
this.nacosDiscoveryProperties.namingServiceInstance().deregisterInstance(
|
this.sidecarNacosDiscoveryProperties.namingServiceInstance()
|
||||||
applicationName, nacosDiscoveryProperties.getGroup(), ip, port);
|
.deregisterInstance(applicationName,
|
||||||
|
sidecarNacosDiscoveryProperties.getGroup(), ip, port);
|
||||||
}
|
}
|
||||||
catch (NacosException e) {
|
catch (NacosException e) {
|
||||||
log.warn("nacos exception happens", e);
|
log.warn("nacos exception happens", e);
|
||||||
|
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2018 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.alibaba.cloud.sidecar.nacos;
|
||||||
|
|
||||||
|
import java.net.SocketException;
|
||||||
|
|
||||||
|
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
||||||
|
import com.alibaba.cloud.sidecar.SidecarProperties;
|
||||||
|
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author yuhuangbin
|
||||||
|
*/
|
||||||
|
public class SidecarNacosDiscoveryProperties extends NacosDiscoveryProperties {
|
||||||
|
|
||||||
|
SidecarProperties sidecarProperties;
|
||||||
|
|
||||||
|
public SidecarNacosDiscoveryProperties(SidecarProperties sidecarProperties) {
|
||||||
|
this.sidecarProperties = sidecarProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() throws SocketException {
|
||||||
|
super.init();
|
||||||
|
|
||||||
|
String ip = sidecarProperties.getIp();
|
||||||
|
if (!StringUtils.isEmpty(ip)) {
|
||||||
|
this.setIp(ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer port = sidecarProperties.getPort();
|
||||||
|
this.setPort(port);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -65,7 +65,6 @@ public class DubboProtocolConfigSupplier implements Supplier<ProtocolConfig> {
|
|||||||
if (protocolConfig == null) {
|
if (protocolConfig == null) {
|
||||||
protocolConfig = new ProtocolConfig();
|
protocolConfig = new ProtocolConfig();
|
||||||
protocolConfig.setName(DEFAULT_PROTOCOL);
|
protocolConfig.setName(DEFAULT_PROTOCOL);
|
||||||
protocolConfig.setPort(-1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return protocolConfig;
|
return protocolConfig;
|
||||||
|
@ -23,6 +23,7 @@ import com.alibaba.cloud.dubbo.util.JSONUtils;
|
|||||||
import org.apache.dubbo.common.URL;
|
import org.apache.dubbo.common.URL;
|
||||||
import org.apache.dubbo.registry.Registry;
|
import org.apache.dubbo.registry.Registry;
|
||||||
import org.apache.dubbo.registry.RegistryFactory;
|
import org.apache.dubbo.registry.RegistryFactory;
|
||||||
|
import org.apache.dubbo.registry.support.AbstractRegistryFactory;
|
||||||
|
|
||||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
@ -37,7 +38,7 @@ import static java.lang.System.getProperty;
|
|||||||
* @see RegistryFactory
|
* @see RegistryFactory
|
||||||
* @see SpringCloudRegistry
|
* @see SpringCloudRegistry
|
||||||
*/
|
*/
|
||||||
public class SpringCloudRegistryFactory implements RegistryFactory {
|
public class SpringCloudRegistryFactory extends AbstractRegistryFactory {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Spring Cloud Protocol.
|
* Spring Cloud Protocol.
|
||||||
@ -65,8 +66,6 @@ public class SpringCloudRegistryFactory implements RegistryFactory {
|
|||||||
|
|
||||||
private DubboGenericServiceFactory dubboGenericServiceFactory;
|
private DubboGenericServiceFactory dubboGenericServiceFactory;
|
||||||
|
|
||||||
private volatile boolean initialized = false;
|
|
||||||
|
|
||||||
public SpringCloudRegistryFactory() {
|
public SpringCloudRegistryFactory() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,9 +75,6 @@ public class SpringCloudRegistryFactory implements RegistryFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void init() {
|
protected void init() {
|
||||||
if (initialized || applicationContext == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.discoveryClient = applicationContext.getBean(DiscoveryClient.class);
|
this.discoveryClient = applicationContext.getBean(DiscoveryClient.class);
|
||||||
this.dubboServiceMetadataRepository = applicationContext
|
this.dubboServiceMetadataRepository = applicationContext
|
||||||
.getBean(DubboServiceMetadataRepository.class);
|
.getBean(DubboServiceMetadataRepository.class);
|
||||||
@ -90,7 +86,7 @@ public class SpringCloudRegistryFactory implements RegistryFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Registry getRegistry(URL url) {
|
public Registry createRegistry(URL url) {
|
||||||
init();
|
init();
|
||||||
return new SpringCloudRegistry(url, discoveryClient,
|
return new SpringCloudRegistry(url, discoveryClient,
|
||||||
dubboServiceMetadataRepository, dubboMetadataConfigServiceProxy,
|
dubboServiceMetadataRepository, dubboMetadataConfigServiceProxy,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user