mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
commit
cb00aeb6dc
10
README-zh.md
10
README-zh.md
@ -39,8 +39,6 @@ Spring Cloud Alibaba 致力于提供微服务开发的一站式解决方案。
|
||||
|
||||
**[Seata](https://github.com/seata/seata)**:阿里巴巴开源产品,一个易于使用的高性能微服务分布式事务解决方案。
|
||||
|
||||
**[Alibaba Cloud ACM](https://www.aliyun.com/product/acm)**:一款在分布式架构环境中对应用配置进行集中管理和推送的应用配置中心产品。
|
||||
|
||||
**[Alibaba Cloud OSS](https://www.aliyun.com/product/oss)**: 阿里云对象存储服务(Object Storage Service,简称 OSS),是阿里云提供的海量、安全、低成本、高可靠的云存储服务。您可以在任何应用、任何时间、任何地点存储和访问任意类型的数据。
|
||||
|
||||
**[Alibaba Cloud SchedulerX](https://help.aliyun.com/document_detail/43136.html)**: 阿里中间件团队开发的一款分布式任务调度产品,提供秒级、精准、高可靠、高可用的定时(基于 Cron 表达式)任务调度服务。
|
||||
@ -97,13 +95,11 @@ Example 列表:
|
||||
|
||||
[Seata Example](https://github.com/alibaba/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/seata-example/readme-zh.md)
|
||||
|
||||
[Alibaba Cloud OSS Example](https://github.com/alibaba/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/oss-example/readme-zh.md)
|
||||
[Alibaba Cloud OSS Example](https://github.com/alibaba/aliyun-spring-boot/tree/master/aliyun-spring-boot-samples/aliyun-oss-spring-boot-sample)
|
||||
|
||||
[Alibaba Cloud ANS Example](https://github.com/alibaba/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/ans-example/ans-provider-example/readme-zh.md)
|
||||
[Alibaba Cloud SMS Example](https://github.com/alibaba/aliyun-spring-boot/tree/master/aliyun-spring-boot-samples/aliyun-sms-spring-boot-sample)
|
||||
|
||||
[Alibaba Cloud ACM Example](https://github.com/alibaba/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/acm-example/acm-local-example/readme-zh.md)
|
||||
|
||||
[Alibaba Cloud SchedulerX Example](https://github.com/alibaba/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/readme-zh.md)
|
||||
[Alibaba Cloud SchedulerX Example](https://github.com/alibaba/aliyun-spring-boot)
|
||||
|
||||
## 版本管理规范
|
||||
|
||||
|
@ -89,8 +89,6 @@ add the module in `dependencies`.
|
||||
|
||||
[Nacos Discovery](https://github.com/alibaba/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc)
|
||||
|
||||
[ACM](https://github.com/alibaba/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-docs/src/main/asciidoc-zh/acm.adoc)
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
@ -106,7 +104,7 @@ Examples:
|
||||
|
||||
[RocketMQ Example](https://github.com/alibaba/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/rocketmq-example/readme.md)
|
||||
|
||||
[Alibaba Cloud OSS Example](https://github.com/alibaba/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/oss-example/readme.md)
|
||||
[Alibaba Cloud OSS Example](https://github.com/alibaba/aliyun-spring-boot/tree/master/aliyun-spring-boot-samples/aliyun-oss-spring-boot-sample)
|
||||
|
||||
[Dubbo Spring Cloud Example](https://github.com/alibaba/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/README_CN.md)
|
||||
|
||||
|
@ -18,10 +18,10 @@
|
||||
<description>Spring Cloud Alibaba Dependencies</description>
|
||||
|
||||
<properties>
|
||||
<revision>2.2.1.RELEASE</revision>
|
||||
<sentinel.version>1.7.2</sentinel.version>
|
||||
<revision>2.2.2-SNAPSHOT</revision>
|
||||
<sentinel.version>1.8.0</sentinel.version>
|
||||
<oss.version>3.1.0</oss.version>
|
||||
<seata.version>1.2.0</seata.version>
|
||||
<seata.version>1.3.0</seata.version>
|
||||
<nacos.client.version>1.3.2</nacos.client.version>
|
||||
<nacos.config.version>0.8.0</nacos.config.version>
|
||||
<spring.context.support.version>1.0.9</spring.context.support.version>
|
||||
|
@ -25,6 +25,7 @@ Before we start the demo, let's learn how to connect Nacos Config to a Spring Cl
|
||||
spring.cloud.nacos.config.server-addr=127.0.0.1:8848
|
||||
|
||||
3. After completing the above two steps, the application will get the externalized configuration from Nacos Server and put it in the Spring Environment's PropertySources.We use the @Value annotation to inject the corresponding configuration into the userName and age fields of the SampleController, and add @RefreshScope to turn on dynamic refresh .
|
||||
|
||||
@RefreshScope
|
||||
class SampleController {
|
||||
|
||||
|
@ -17,7 +17,8 @@
|
||||
package com.alibaba.cloud.dubbo.bootstrap;
|
||||
|
||||
import com.alibaba.cloud.dubbo.service.EchoService;
|
||||
import org.apache.dubbo.config.annotation.Reference;
|
||||
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@ -33,7 +34,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RestController
|
||||
public class DubboSpringCloudClientBootstrap {
|
||||
|
||||
@Reference
|
||||
@DubboReference
|
||||
private EchoService echoService;
|
||||
|
||||
@GetMapping("/echo")
|
||||
|
@ -1,8 +1,9 @@
|
||||
dubbo:
|
||||
registry:
|
||||
address: spring-cloud://localhost
|
||||
cloud:
|
||||
subscribed-services: spring-cloud-alibaba-dubbo-server
|
||||
protocols:
|
||||
dubbo:
|
||||
port: -1
|
||||
|
||||
spring:
|
||||
application:
|
||||
|
@ -23,7 +23,8 @@ import com.alibaba.cloud.dubbo.annotation.DubboTransported;
|
||||
import com.alibaba.cloud.dubbo.service.RestService;
|
||||
import com.alibaba.cloud.dubbo.service.User;
|
||||
import com.alibaba.cloud.dubbo.service.UserService;
|
||||
import org.apache.dubbo.config.annotation.Reference;
|
||||
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@ -60,10 +61,10 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
||||
@EnableCaching
|
||||
public class DubboSpringCloudConsumerBootstrap {
|
||||
|
||||
@Reference
|
||||
@DubboReference
|
||||
private UserService userService;
|
||||
|
||||
@Reference(version = "1.0.0", protocol = "dubbo")
|
||||
@DubboReference(version = "1.0.0", protocol = "dubbo")
|
||||
private RestService restService;
|
||||
|
||||
@Autowired
|
||||
|
@ -1,15 +1,10 @@
|
||||
dubbo:
|
||||
registry:
|
||||
# The Spring Cloud Dubbo's registry extension
|
||||
## the default value of dubbo-provider-services is "*", that means to subscribe all providers,
|
||||
## thus it's optimized if subscriber specifies the required providers.
|
||||
address: spring-cloud://localhost
|
||||
# The traditional Dubbo's registry also is supported
|
||||
# address: zookeeper://127.0.0.1:2181
|
||||
cloud:
|
||||
# The subscribed services in consumer side
|
||||
subscribed-services: ${provider.application.name}
|
||||
|
||||
protocols:
|
||||
dubbo:
|
||||
port: -1
|
||||
consumer:
|
||||
check: false
|
||||
|
||||
|
@ -20,12 +20,12 @@ import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.dubbo.config.annotation.Service;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
|
||||
/**
|
||||
* In-Memory {@link UserService} implementation.
|
||||
*/
|
||||
@Service(protocol = "dubbo")
|
||||
@DubboService(protocol = "dubbo")
|
||||
public class InMemoryUserService implements UserService {
|
||||
|
||||
private Map<Long, User> usersRepository = new HashMap<>();
|
||||
|
@ -30,7 +30,8 @@ import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.apache.dubbo.config.annotation.Service;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -42,7 +43,7 @@ import static org.springframework.util.MimeTypeUtils.APPLICATION_JSON_VALUE;
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
@Service(version = "1.0.0", protocol = { "dubbo", "rest" })
|
||||
@DubboService(version = "1.0.0", protocol = { "dubbo", "rest" })
|
||||
@Path("/")
|
||||
public class StandardRestService implements RestService {
|
||||
|
||||
|
@ -9,11 +9,6 @@ dubbo:
|
||||
name: rest
|
||||
port: 9090
|
||||
server: netty
|
||||
registry:
|
||||
# The Spring Cloud Dubbo's registry extension
|
||||
address: spring-cloud://localhost
|
||||
# The traditional Dubbo's registry
|
||||
# address: zookeeper://127.0.0.1:2181
|
||||
feign:
|
||||
hystrix:
|
||||
enabled: true
|
@ -20,12 +20,12 @@ import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.dubbo.config.annotation.Service;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
|
||||
/**
|
||||
* In-Memory {@link UserService} implementation.
|
||||
*/
|
||||
@Service(protocol = "dubbo")
|
||||
@DubboService(protocol = "dubbo")
|
||||
public class InMemoryUserService implements UserService {
|
||||
|
||||
private Map<Long, User> usersRepository = new HashMap<>();
|
||||
|
@ -19,7 +19,8 @@ package com.alibaba.cloud.dubbo.service;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.dubbo.config.annotation.Service;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -39,7 +40,7 @@ import static com.alibaba.cloud.dubbo.util.LoggerUtils.log;
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
@Service(version = "1.0.0")
|
||||
@DubboService(version = "1.0.0")
|
||||
@RestController
|
||||
public class SpringRestService implements RestService {
|
||||
|
||||
|
@ -3,16 +3,7 @@ dubbo:
|
||||
base-packages: com.alibaba.cloud.dubbo.service
|
||||
protocols:
|
||||
dubbo:
|
||||
name: dubbo
|
||||
port: -1
|
||||
registries:
|
||||
new:
|
||||
address: spring-cloud://localhost
|
||||
# registry:
|
||||
# The Spring Cloud Dubbo's registry extension
|
||||
# address: spring-cloud://localhost
|
||||
# The traditional Dubbo's registry
|
||||
# address: nacos://127.0.0.1:8848
|
||||
|
||||
feign:
|
||||
hystrix:
|
||||
|
@ -17,7 +17,8 @@
|
||||
package com.alibaba.cloud.dubbo.bootstrap;
|
||||
|
||||
import com.alibaba.cloud.dubbo.service.EchoService;
|
||||
import org.apache.dubbo.config.annotation.Service;
|
||||
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@ -36,7 +37,7 @@ public class DubboSpringCloudServerBootstrap {
|
||||
|
||||
}
|
||||
|
||||
@Service
|
||||
@DubboService
|
||||
class EchoServiceImpl implements EchoService {
|
||||
|
||||
@Override
|
||||
|
@ -4,8 +4,6 @@ dubbo:
|
||||
protocol:
|
||||
name: dubbo
|
||||
port: -1
|
||||
registry:
|
||||
address: spring-cloud://localhost
|
||||
|
||||
spring:
|
||||
application:
|
||||
|
@ -22,6 +22,7 @@
|
||||
<module>spring-cloud-starter-stream-rocketmq</module>
|
||||
<module>spring-cloud-starter-bus-rocketmq</module>
|
||||
<module>spring-cloud-starter-dubbo</module>
|
||||
<module>spring-cloud-starter-dubbo-gateway</module>
|
||||
<module>spring-cloud-starter-alibaba-sidecar</module>
|
||||
<module>spring-cloud-circuitbreaker-sentinel</module>
|
||||
<module>spring-cloud-starter-alibaba-sentinel</module>
|
||||
|
@ -59,6 +59,7 @@
|
||||
<artifactId>spring-cloud-starter-gateway</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
|
@ -91,7 +91,7 @@ public class SentinelSCGAutoConfiguration {
|
||||
}
|
||||
|
||||
private void initAppType() {
|
||||
System.setProperty(SentinelConfig.APP_TYPE, ConfigConstants.APP_TYPE_SCG_GATEWAY);
|
||||
System.setProperty(SentinelConfig.APP_TYPE_PROP_KEY, ConfigConstants.APP_TYPE_SCG_GATEWAY);
|
||||
}
|
||||
|
||||
private void initFallback() {
|
||||
|
@ -65,7 +65,7 @@ public class SentinelZuulAutoConfiguration {
|
||||
private void init() {
|
||||
requestOriginParserOptional
|
||||
.ifPresent(ZuulGatewayCallbackManager::setOriginParser);
|
||||
System.setProperty(SentinelConfig.APP_TYPE,
|
||||
System.setProperty(SentinelConfig.APP_TYPE_PROP_KEY,
|
||||
String.valueOf(ConfigConstants.APP_TYPE_ZUUL_GATEWAY));
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ public class ReactiveSentinelCircuitBreakerIntegrationTest {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
// Recovered.
|
||||
// Half-open recovery (will re-open the circuit breaker).
|
||||
StepVerifier.create(service.slow()).expectNext("slow").verifyComplete();
|
||||
|
||||
StepVerifier.create(service.normalFlux()).expectNext("normalflux")
|
||||
@ -99,7 +99,7 @@ public class ReactiveSentinelCircuitBreakerIntegrationTest {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
// Recovered.
|
||||
// Half-open recovery (will re-open the circuit breaker).
|
||||
StepVerifier.create(service.slowFlux()).expectNext("slowflux").verifyComplete();
|
||||
}
|
||||
|
||||
@ -110,7 +110,7 @@ public class ReactiveSentinelCircuitBreakerIntegrationTest {
|
||||
|
||||
@GetMapping("/slow")
|
||||
public Mono<String> slow() {
|
||||
return Mono.just("slow").delayElement(Duration.ofMillis(500));
|
||||
return Mono.just("slow").delayElement(Duration.ofMillis(80));
|
||||
}
|
||||
|
||||
@GetMapping("/normal")
|
||||
@ -120,7 +120,7 @@ public class ReactiveSentinelCircuitBreakerIntegrationTest {
|
||||
|
||||
@GetMapping("/slow_flux")
|
||||
public Flux<String> slowFlux() {
|
||||
return Flux.just("slow", "flux").delayElements(Duration.ofMillis(500));
|
||||
return Flux.just("slow", "flux").delayElements(Duration.ofMillis(80));
|
||||
}
|
||||
|
||||
@GetMapping("normal_flux")
|
||||
@ -133,19 +133,19 @@ public class ReactiveSentinelCircuitBreakerIntegrationTest {
|
||||
return factory -> {
|
||||
factory.configure(builder -> builder
|
||||
.rules(Collections.singletonList(new DegradeRule("slow_mono")
|
||||
.setGrade(RuleConstant.DEGRADE_GRADE_RT).setCount(100)
|
||||
.setTimeWindow(5))),
|
||||
.setCount(50).setSlowRatioThreshold(0.7).setMinRequestAmount(5)
|
||||
.setStatIntervalMs(30000).setTimeWindow(5))),
|
||||
"slow_mono");
|
||||
factory.configure(builder -> builder
|
||||
.rules(Collections.singletonList(new DegradeRule("slow_flux")
|
||||
.setGrade(RuleConstant.DEGRADE_GRADE_RT).setCount(100)
|
||||
.setTimeWindow(5))),
|
||||
.rules(Collections.singletonList(new DegradeRule("slow_mono")
|
||||
.setCount(50).setSlowRatioThreshold(0.7).setMinRequestAmount(5)
|
||||
.setStatIntervalMs(30000).setTimeWindow(5))),
|
||||
"slow_flux");
|
||||
factory.configureDefault(id -> new SentinelConfigBuilder()
|
||||
.resourceName(id)
|
||||
.rules(Collections.singletonList(new DegradeRule(id)
|
||||
.setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT)
|
||||
.setCount(0.5).setTimeWindow(10)))
|
||||
.setCount(5).setTimeWindow(10)))
|
||||
.build());
|
||||
};
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@ -59,21 +60,24 @@ public class SentinelCircuitBreakerIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void testSlow() throws Exception {
|
||||
// The first 5 requests should pass.
|
||||
assertThat(service.slow()).isEqualTo("slow");
|
||||
assertThat(service.slow()).isEqualTo("slow");
|
||||
assertThat(service.slow()).isEqualTo("slow");
|
||||
assertThat(service.slow()).isEqualTo("slow");
|
||||
assertThat(service.slow()).isEqualTo("slow");
|
||||
assertThat(service.slow(true)).isEqualTo("slow");
|
||||
assertThat(service.slow(true)).isEqualTo("slow");
|
||||
assertThat(service.slow(true)).isEqualTo("slow");
|
||||
assertThat(service.slow(false)).isEqualTo("slow");
|
||||
assertThat(service.slow(false)).isEqualTo("slow");
|
||||
assertThat(service.slow(true)).isEqualTo("slow");
|
||||
assertThat(service.slow(true)).isEqualTo("slow");
|
||||
|
||||
// Then in the next 10s, the fallback method should be called.
|
||||
for (int i = 0; i < 10; i++) {
|
||||
assertThat(service.slow()).isEqualTo("fallback");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
assertThat(service.slow(true)).isEqualTo("fallback");
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
// Try a normal request.
|
||||
assertThat(service.slow(false)).isEqualTo("slow");
|
||||
// Recovered.
|
||||
assertThat(service.slow()).isEqualTo("slow");
|
||||
assertThat(service.slow(true)).isEqualTo("slow");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -97,8 +101,10 @@ public class SentinelCircuitBreakerIntegrationTest {
|
||||
protected static class Application {
|
||||
|
||||
@GetMapping("/slow")
|
||||
public String slow() throws InterruptedException {
|
||||
Thread.sleep(500);
|
||||
public String slow(@RequestParam(required = false) Boolean slow) throws InterruptedException {
|
||||
if (slow == null || slow) {
|
||||
Thread.sleep(80);
|
||||
}
|
||||
return "slow";
|
||||
}
|
||||
|
||||
@ -112,14 +118,15 @@ public class SentinelCircuitBreakerIntegrationTest {
|
||||
String slowId = "slow";
|
||||
List<DegradeRule> rules = Collections.singletonList(
|
||||
new DegradeRule(slowId).setGrade(RuleConstant.DEGRADE_GRADE_RT)
|
||||
.setCount(100).setTimeWindow(10));
|
||||
.setCount(50).setSlowRatioThreshold(0.7).setMinRequestAmount(5)
|
||||
.setStatIntervalMs(30000).setTimeWindow(5));
|
||||
return factory -> {
|
||||
factory.configure(builder -> builder.rules(rules), slowId);
|
||||
factory.configureDefault(id -> new SentinelConfigBuilder()
|
||||
.resourceName(id)
|
||||
.rules(Collections.singletonList(new DegradeRule(id)
|
||||
.setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT)
|
||||
.setCount(0.5).setTimeWindow(10)))
|
||||
.setCount(10).setStatIntervalMs(10000).setTimeWindow(10)))
|
||||
.build());
|
||||
};
|
||||
}
|
||||
@ -137,9 +144,9 @@ public class SentinelCircuitBreakerIntegrationTest {
|
||||
this.cbFactory = cbFactory;
|
||||
}
|
||||
|
||||
public String slow() {
|
||||
public String slow(boolean slow) {
|
||||
return cbFactory.create("slow").run(
|
||||
() -> rest.getForObject("/slow", String.class), t -> "fallback");
|
||||
() -> rest.getForObject("/slow?slow=" + slow, String.class), t -> "fallback");
|
||||
}
|
||||
|
||||
public String normal() {
|
||||
|
@ -19,7 +19,6 @@ package com.alibaba.cloud.nacos;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -29,9 +28,8 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import com.alibaba.nacos.api.NacosFactory;
|
||||
import com.alibaba.nacos.api.naming.NamingMaintainFactory;
|
||||
import com.alibaba.nacos.api.naming.NamingMaintainService;
|
||||
import com.alibaba.nacos.api.naming.NamingService;
|
||||
import com.alibaba.nacos.api.naming.PreservedMetadataKeys;
|
||||
@ -48,6 +46,8 @@ import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static com.alibaba.nacos.api.NacosFactory.createMaintainService;
|
||||
import static com.alibaba.nacos.api.NacosFactory.createNamingService;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.ACCESS_KEY;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.CLUSTER_NAME;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT;
|
||||
@ -215,13 +215,12 @@ public class NacosDiscoveryProperties {
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
private static NamingService namingService;
|
||||
private NamingService namingService;
|
||||
|
||||
private static NamingMaintainService namingMaintainService;
|
||||
private NamingMaintainService namingMaintainService;
|
||||
|
||||
@PostConstruct
|
||||
public void init() throws SocketException {
|
||||
namingService = null;
|
||||
public void init() throws Exception {
|
||||
|
||||
metadata.put(PreservedMetadataKeys.REGISTER_SOURCE, "SPRING_CLOUD");
|
||||
if (secure) {
|
||||
@ -268,6 +267,15 @@ public class NacosDiscoveryProperties {
|
||||
}
|
||||
|
||||
this.overrideFromEnv(environment);
|
||||
|
||||
Properties properties = getNacosProperties();
|
||||
this.namingService = createNamingService(properties);
|
||||
this.namingMaintainService = createMaintainService(properties);
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void destroy() {
|
||||
|
||||
}
|
||||
|
||||
public String getEndpoint() {
|
||||
@ -538,36 +546,11 @@ public class NacosDiscoveryProperties {
|
||||
}
|
||||
|
||||
public NamingService namingServiceInstance() {
|
||||
|
||||
if (null != namingService) {
|
||||
return namingService;
|
||||
}
|
||||
|
||||
try {
|
||||
namingService = NacosFactory.createNamingService(getNacosProperties());
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("create naming service error!properties={},e=,", this, e);
|
||||
return null;
|
||||
}
|
||||
return namingService;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public NamingMaintainService namingMaintainServiceInstance() {
|
||||
|
||||
if (null != namingMaintainService) {
|
||||
return namingMaintainService;
|
||||
}
|
||||
|
||||
try {
|
||||
namingMaintainService = NamingMaintainFactory
|
||||
.createMaintainService(getNacosProperties());
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("create naming service error!properties={},e=,", this, e);
|
||||
return null;
|
||||
}
|
||||
return namingMaintainService;
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,7 @@ public class NacosServiceDiscovery {
|
||||
if (instance.getMetadata() != null) {
|
||||
metadata.putAll(instance.getMetadata());
|
||||
}
|
||||
metadata.put("nacos.ephemeral",String.valueOf(instance.isEphemeral()));
|
||||
metadata.put("nacos.ephemeral", String.valueOf(instance.isEphemeral()));
|
||||
nacosServiceInstance.setMetadata(metadata);
|
||||
|
||||
if (metadata.containsKey("secure")) {
|
||||
|
@ -44,7 +44,9 @@ import org.springframework.web.context.request.RequestContextHolder;
|
||||
*/
|
||||
public class SeataHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(SeataHystrixConcurrencyStrategy.class);
|
||||
private final Logger logger = LoggerFactory
|
||||
.getLogger(SeataHystrixConcurrencyStrategy.class);
|
||||
|
||||
private HystrixConcurrencyStrategy delegate;
|
||||
|
||||
public SeataHystrixConcurrencyStrategy() {
|
||||
@ -53,45 +55,54 @@ public class SeataHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy
|
||||
if (this.delegate instanceof SeataHystrixConcurrencyStrategy) {
|
||||
return;
|
||||
}
|
||||
HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook();
|
||||
HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier();
|
||||
HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher();
|
||||
HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy();
|
||||
logCurrentStateOfHystrixPlugins(eventNotifier, metricsPublisher, propertiesStrategy);
|
||||
HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins
|
||||
.getInstance().getCommandExecutionHook();
|
||||
HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance()
|
||||
.getEventNotifier();
|
||||
HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance()
|
||||
.getMetricsPublisher();
|
||||
HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance()
|
||||
.getPropertiesStrategy();
|
||||
logCurrentStateOfHystrixPlugins(eventNotifier, metricsPublisher,
|
||||
propertiesStrategy);
|
||||
HystrixPlugins.reset();
|
||||
HystrixPlugins.getInstance().registerConcurrencyStrategy(this);
|
||||
HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook);
|
||||
HystrixPlugins.getInstance()
|
||||
.registerCommandExecutionHook(commandExecutionHook);
|
||||
HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
|
||||
HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
|
||||
HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
catch (Exception ex) {
|
||||
logger.error("Failed to register Seata Hystrix Concurrency Strategy", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void logCurrentStateOfHystrixPlugins(HystrixEventNotifier eventNotifier,
|
||||
HystrixMetricsPublisher metricsPublisher,
|
||||
HystrixPropertiesStrategy propertiesStrategy) {
|
||||
HystrixMetricsPublisher metricsPublisher,
|
||||
HystrixPropertiesStrategy propertiesStrategy) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Current Hystrix plugins configuration is [" + "concurrencyStrategy [" + this.delegate + "],"
|
||||
+ "eventNotifier [" + eventNotifier + "]," + "metricPublisher [" + metricsPublisher + "],"
|
||||
+ "propertiesStrategy [" + propertiesStrategy + "]," + "]");
|
||||
logger.debug("Current Hystrix plugins configuration is ["
|
||||
+ "concurrencyStrategy [" + this.delegate + "]," + "eventNotifier ["
|
||||
+ eventNotifier + "]," + "metricPublisher [" + metricsPublisher + "],"
|
||||
+ "propertiesStrategy [" + propertiesStrategy + "]," + "]");
|
||||
logger.debug("Registering Seata Hystrix Concurrency Strategy.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThreadPoolExecutor getThreadPool(HystrixThreadPoolKey threadPoolKey, HystrixProperty<Integer> corePoolSize,
|
||||
HystrixProperty<Integer> maximumPoolSize,
|
||||
HystrixProperty<Integer> keepAliveTime, TimeUnit unit,
|
||||
BlockingQueue<Runnable> workQueue) {
|
||||
return this.delegate.getThreadPool(threadPoolKey, corePoolSize, maximumPoolSize, keepAliveTime, unit,
|
||||
workQueue);
|
||||
public ThreadPoolExecutor getThreadPool(HystrixThreadPoolKey threadPoolKey,
|
||||
HystrixProperty<Integer> corePoolSize,
|
||||
HystrixProperty<Integer> maximumPoolSize,
|
||||
HystrixProperty<Integer> keepAliveTime, TimeUnit unit,
|
||||
BlockingQueue<Runnable> workQueue) {
|
||||
return this.delegate.getThreadPool(threadPoolKey, corePoolSize, maximumPoolSize,
|
||||
keepAliveTime, unit, workQueue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThreadPoolExecutor getThreadPool(HystrixThreadPoolKey threadPoolKey,
|
||||
HystrixThreadPoolProperties threadPoolProperties) {
|
||||
HystrixThreadPoolProperties threadPoolProperties) {
|
||||
return this.delegate.getThreadPool(threadPoolKey, threadPoolProperties);
|
||||
}
|
||||
|
||||
@ -101,7 +112,8 @@ public class SeataHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> HystrixRequestVariable<T> getRequestVariable(HystrixRequestVariableLifecycle<T> rv) {
|
||||
public <T> HystrixRequestVariable<T> getRequestVariable(
|
||||
HystrixRequestVariableLifecycle<T> rv) {
|
||||
return this.delegate.getRequestVariable(rv);
|
||||
}
|
||||
|
||||
@ -114,14 +126,16 @@ public class SeataHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy
|
||||
Callable<K> wrappedCallable;
|
||||
if (this.delegate != null) {
|
||||
wrappedCallable = this.delegate.wrapCallable(c);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
wrappedCallable = c;
|
||||
}
|
||||
if (wrappedCallable instanceof SeataContextCallable) {
|
||||
return wrappedCallable;
|
||||
}
|
||||
|
||||
return new SeataContextCallable<>(wrappedCallable, RequestContextHolder.getRequestAttributes());
|
||||
return new SeataContextCallable<>(wrappedCallable,
|
||||
RequestContextHolder.getRequestAttributes());
|
||||
}
|
||||
|
||||
private static class SeataContextCallable<K> implements Callable<K> {
|
||||
@ -144,7 +158,8 @@ public class SeataHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy
|
||||
RequestContextHolder.setRequestAttributes(requestAttributes);
|
||||
RootContext.bind(xid);
|
||||
return actual.call();
|
||||
} finally {
|
||||
}
|
||||
finally {
|
||||
RootContext.unbind();
|
||||
RequestContextHolder.resetRequestAttributes();
|
||||
}
|
||||
|
@ -31,7 +31,6 @@ import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule;
|
||||
import com.alibaba.csp.sentinel.slots.system.SystemRule;
|
||||
import com.alibaba.csp.sentinel.transport.config.TransportConfig;
|
||||
import com.alibaba.csp.sentinel.util.AppNameUtil;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||
@ -79,9 +78,9 @@ public class SentinelAutoConfiguration {
|
||||
System.setProperty(LogBase.LOG_NAME_USE_PID,
|
||||
String.valueOf(properties.getLog().isSwitchPid()));
|
||||
}
|
||||
if (StringUtils.isEmpty(System.getProperty(AppNameUtil.APP_NAME))
|
||||
if (StringUtils.isEmpty(System.getProperty(SentinelConfig.APP_NAME_PROP_KEY))
|
||||
&& StringUtils.hasText(projectName)) {
|
||||
System.setProperty(AppNameUtil.APP_NAME, projectName);
|
||||
System.setProperty(SentinelConfig.APP_NAME_PROP_KEY, projectName);
|
||||
}
|
||||
if (StringUtils.isEmpty(System.getProperty(TransportConfig.SERVER_PORT))
|
||||
&& StringUtils.hasText(properties.getTransport().getPort())) {
|
||||
|
@ -28,8 +28,6 @@ import com.alibaba.csp.sentinel.config.SentinelConfig;
|
||||
import com.alibaba.csp.sentinel.log.LogBase;
|
||||
import com.alibaba.csp.sentinel.slots.block.BlockException;
|
||||
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
|
||||
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
|
||||
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
|
||||
import com.alibaba.csp.sentinel.transport.config.TransportConfig;
|
||||
@ -116,13 +114,6 @@ public class SentinelAutoConfigurationTests {
|
||||
rule.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_DEFAULT);
|
||||
rule.setStrategy(RuleConstant.STRATEGY_DIRECT);
|
||||
FlowRuleManager.loadRules(Arrays.asList(rule));
|
||||
|
||||
DegradeRule degradeRule = new DegradeRule();
|
||||
degradeRule.setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT);
|
||||
degradeRule.setResource("GET:" + degradeUrl);
|
||||
degradeRule.setCount(0);
|
||||
degradeRule.setTimeWindow(60);
|
||||
DegradeRuleManager.loadRules(Arrays.asList(degradeRule));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -208,7 +199,7 @@ public class SentinelAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlowRestTemplate() {
|
||||
public void testRestTemplateBlockHandler() {
|
||||
|
||||
assertThat(restTemplate.getInterceptors().size()).isEqualTo(2);
|
||||
assertThat(restTemplateWithBlockClass.getInterceptors().size()).isEqualTo(1);
|
||||
@ -236,15 +227,6 @@ public class SentinelAutoConfigurationTests {
|
||||
}).isInstanceOf(RestClientException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFallbackRestTemplate() {
|
||||
ResponseEntity responseEntity = restTemplateWithFallbackClass
|
||||
.getForEntity(degradeUrl, String.class);
|
||||
|
||||
assertThat(responseEntity.getBody()).isEqualTo("Oops fallback");
|
||||
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class SentinelTestConfiguration {
|
||||
|
||||
|
@ -16,8 +16,6 @@
|
||||
|
||||
package com.alibaba.cloud.sidecar.nacos;
|
||||
|
||||
import java.net.SocketException;
|
||||
|
||||
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
||||
import com.alibaba.cloud.sidecar.SidecarProperties;
|
||||
|
||||
@ -35,7 +33,7 @@ public class SidecarNacosDiscoveryProperties extends NacosDiscoveryProperties {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() throws SocketException {
|
||||
public void init() throws Exception {
|
||||
super.init();
|
||||
|
||||
String ip = sidecarProperties.getIp();
|
||||
|
@ -0,0 +1,167 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<parent>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-starters</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>spring-cloud-starter-dubbo-gateway</artifactId>
|
||||
<name>Spring Cloud Starter Dubbo Gateway</name>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- Spring Boot dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-actuator</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Cloud dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-commons</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-context</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- <!– Zuul –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.cloud</groupId>-->
|
||||
<!-- <artifactId>spring-cloud-starter-netflix-zuul</artifactId>-->
|
||||
<!-- <optional>true</optional>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<!-- Spring Cloud Gateway -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-gateway</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- Dubbo Spring Cloud Starter -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-dubbo</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.11</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Testing -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- <!– Eureka Service Discovery –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.cloud</groupId>-->
|
||||
<!-- <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>-->
|
||||
<!-- <scope>test</scope>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<!-- Zookeeper Service Discovery -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
|
||||
<version>${spring-cloud-zookeeper.version}</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.apache.zookeeper</groupId>
|
||||
<artifactId>zookeeper</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.zookeeper</groupId>
|
||||
<artifactId>zookeeper</artifactId>
|
||||
<version>3.4.14</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-framework</artifactId>
|
||||
<version>${curator.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- <!– Spring Cloud Consul –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.cloud</groupId>-->
|
||||
<!-- <artifactId>spring-cloud-starter-consul-discovery</artifactId>-->
|
||||
<!-- <version>${spring-cloud-consul.version}</version>-->
|
||||
<!-- <scope>test</scope>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<!-- <!– Nacos Service Discovery –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.alibaba.cloud</groupId>-->
|
||||
<!-- <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>-->
|
||||
<!-- <scope>test</scope>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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
|
||||
*
|
||||
* http://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.dubbo.gateway;
|
||||
|
||||
import com.alibaba.cloud.dubbo.util.DubboCloudConstants;
|
||||
|
||||
/**
|
||||
* The constants of Dubbo Cloud Gateway
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
public interface DubboCloudGatewayConstants {
|
||||
|
||||
/**
|
||||
* The property prefix of Configuration
|
||||
*/
|
||||
String CONFIG_PROPERTY_PREFIX = DubboCloudConstants.CONFIG_PROPERTY_PREFIX
|
||||
+ ".gateway";
|
||||
|
||||
}
|
@ -0,0 +1,166 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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
|
||||
*
|
||||
* http://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.dubbo.gateway;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.cloud.dubbo.http.MutableHttpServerRequest;
|
||||
import com.alibaba.cloud.dubbo.metadata.DubboRestServiceMetadata;
|
||||
import com.alibaba.cloud.dubbo.metadata.RequestMetadata;
|
||||
import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata;
|
||||
import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository;
|
||||
import com.alibaba.cloud.dubbo.service.DubboGenericServiceExecutionContext;
|
||||
import com.alibaba.cloud.dubbo.service.DubboGenericServiceExecutionContextFactory;
|
||||
import com.alibaba.cloud.dubbo.service.DubboGenericServiceFactory;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.apache.dubbo.rpc.service.GenericException;
|
||||
import org.apache.dubbo.rpc.service.GenericService;
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.format.support.DefaultFormattingConversionService;
|
||||
import org.springframework.http.HttpRequest;
|
||||
|
||||
import static com.alibaba.cloud.dubbo.http.util.HttpUtils.getParameters;
|
||||
import static org.apache.commons.lang3.StringUtils.substringAfter;
|
||||
import static org.apache.commons.lang3.StringUtils.substringBetween;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR;
|
||||
|
||||
/**
|
||||
* The executor of Dubbo Cloud Gateway that handles the HTTP request and responses the
|
||||
* result of execution of the generic invocation to the Dubbo service providers
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*
|
||||
*/
|
||||
public class DubboCloudGatewayExecutor {
|
||||
|
||||
private final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private final DubboServiceMetadataRepository repository;
|
||||
|
||||
private final DubboGenericServiceFactory serviceFactory;
|
||||
|
||||
private final DubboGenericServiceExecutionContextFactory contextFactory;
|
||||
|
||||
private final DubboCloudGatewayProperties dubboCloudGatewayProperties;
|
||||
|
||||
private final ConversionService conversionService;
|
||||
|
||||
private final Map<String, Object> dubboTranslatedAttributes = new HashMap<>();
|
||||
|
||||
public DubboCloudGatewayExecutor(DubboServiceMetadataRepository repository,
|
||||
DubboGenericServiceFactory serviceFactory,
|
||||
DubboGenericServiceExecutionContextFactory contextFactory,
|
||||
DubboCloudGatewayProperties dubboCloudGatewayProperties,
|
||||
ObjectProvider<ConversionService> conversionServices) {
|
||||
this.repository = repository;
|
||||
this.serviceFactory = serviceFactory;
|
||||
this.contextFactory = contextFactory;
|
||||
this.dubboCloudGatewayProperties = dubboCloudGatewayProperties;
|
||||
this.conversionService = conversionServices
|
||||
.getIfAvailable(DefaultFormattingConversionService::new);
|
||||
// TODO : Replace these hard-code configurations
|
||||
this.dubboTranslatedAttributes.put("protocol", "dubbo");
|
||||
this.dubboTranslatedAttributes.put("cluster", "failover");
|
||||
}
|
||||
|
||||
public Object execute(HttpRequest request) {
|
||||
|
||||
String serviceName = resolveServiceName(request);
|
||||
|
||||
String restPath = substringAfter(request.getURI().getPath(), serviceName);
|
||||
|
||||
// 初始化 serviceName 的 REST 请求元数据
|
||||
repository.initializeMetadata(serviceName);
|
||||
// 将 HttpServletRequest 转化为 RequestMetadata
|
||||
RequestMetadata clientMetadata = buildRequestMetadata(request, restPath);
|
||||
|
||||
DubboRestServiceMetadata dubboRestServiceMetadata = repository.get(serviceName,
|
||||
clientMetadata);
|
||||
|
||||
Object result = null;
|
||||
|
||||
if (dubboRestServiceMetadata != null) {
|
||||
|
||||
RestMethodMetadata dubboRestMethodMetadata = dubboRestServiceMetadata
|
||||
.getRestMethodMetadata();
|
||||
|
||||
GenericService genericService = serviceFactory
|
||||
.create(dubboRestServiceMetadata, dubboTranslatedAttributes);
|
||||
|
||||
byte[] body = getRequestBody(request);
|
||||
|
||||
MutableHttpServerRequest httpServerRequest = new MutableHttpServerRequest(
|
||||
request, body);
|
||||
|
||||
DubboGenericServiceExecutionContext context = contextFactory
|
||||
.create(dubboRestMethodMetadata, httpServerRequest);
|
||||
|
||||
GenericException exception = null;
|
||||
|
||||
try {
|
||||
result = genericService.$invoke(context.getMethodName(),
|
||||
context.getParameterTypes(), context.getParameters());
|
||||
|
||||
String returnType = dubboRestMethodMetadata.getReturnType();
|
||||
|
||||
logger.info("The result is " + result);
|
||||
|
||||
}
|
||||
catch (GenericException e) {
|
||||
exception = e;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
private String resolveServiceName(HttpRequest request) {
|
||||
URI uri = request.getURI();
|
||||
String requestURI = uri.getPath();
|
||||
String servletPath = dubboCloudGatewayProperties.getContextPath();
|
||||
String part = substringAfter(requestURI, servletPath);
|
||||
String serviceName = substringBetween(part, PATH_SEPARATOR, PATH_SEPARATOR);
|
||||
return serviceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO : Get the Request Body from HttpRequest
|
||||
*
|
||||
* @param request {@link HttpRequest}
|
||||
* @return
|
||||
*/
|
||||
private byte[] getRequestBody(HttpRequest request) {
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
private RequestMetadata buildRequestMetadata(HttpRequest request, String restPath) {
|
||||
RequestMetadata requestMetadata = new RequestMetadata();
|
||||
requestMetadata.setPath(restPath);
|
||||
requestMetadata.setMethod(request.getMethod().toString());
|
||||
requestMetadata.setParams(getParameters(request));
|
||||
requestMetadata.setHeaders(request.getHeaders());
|
||||
return requestMetadata;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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
|
||||
*
|
||||
* http://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.dubbo.gateway;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import static com.alibaba.cloud.dubbo.gateway.DubboCloudGatewayConstants.CONFIG_PROPERTY_PREFIX;
|
||||
|
||||
/**
|
||||
* The Configuration Properties for Dubbo Cloud Gateway
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
@ConfigurationProperties(prefix = CONFIG_PROPERTY_PREFIX)
|
||||
public class DubboCloudGatewayProperties {
|
||||
|
||||
/**
|
||||
* Enabled or not
|
||||
*/
|
||||
private boolean enabled = true;
|
||||
|
||||
/**
|
||||
* The context path for the gateway request mapping
|
||||
*/
|
||||
private String contextPath = "";
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public String getContextPath() {
|
||||
return contextPath;
|
||||
}
|
||||
|
||||
public void setContextPath(String contextPath) {
|
||||
this.contextPath = contextPath;
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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
|
||||
*
|
||||
* http://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.dubbo.gateway.autoconfigure;
|
||||
|
||||
import com.alibaba.cloud.dubbo.autoconfigure.DubboMetadataAutoConfiguration;
|
||||
import com.alibaba.cloud.dubbo.autoconfigure.DubboServiceAutoConfiguration;
|
||||
import com.alibaba.cloud.dubbo.gateway.DubboCloudGatewayExecutor;
|
||||
import com.alibaba.cloud.dubbo.gateway.DubboCloudGatewayProperties;
|
||||
import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository;
|
||||
import com.alibaba.cloud.dubbo.service.DubboGenericServiceExecutionContextFactory;
|
||||
import com.alibaba.cloud.dubbo.service.DubboGenericServiceFactory;
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnProperty(prefix = "dubbo.cloud.gateway", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@AutoConfigureAfter({ DubboServiceAutoConfiguration.class,
|
||||
DubboMetadataAutoConfiguration.class })
|
||||
@EnableConfigurationProperties(DubboCloudGatewayProperties.class)
|
||||
public class DubboCloudGatewayAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(DubboCloudGatewayExecutor.class)
|
||||
public DubboCloudGatewayExecutor dubboCloudGatewayExecutor(
|
||||
DubboServiceMetadataRepository repository,
|
||||
DubboGenericServiceFactory serviceFactory,
|
||||
DubboGenericServiceExecutionContextFactory contextFactory,
|
||||
DubboCloudGatewayProperties dubboCloudGatewayProperties,
|
||||
ObjectProvider<ConversionService> conversionServices) {
|
||||
return new DubboCloudGatewayExecutor(repository, serviceFactory, contextFactory,
|
||||
dubboCloudGatewayProperties, conversionServices);
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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
|
||||
*
|
||||
* http://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.dubbo.gateway.standard;
|
||||
|
||||
import com.alibaba.cloud.dubbo.autoconfigure.DubboMetadataAutoConfiguration;
|
||||
import com.alibaba.cloud.dubbo.autoconfigure.DubboServiceAutoConfiguration;
|
||||
import com.alibaba.cloud.dubbo.gateway.DubboCloudGatewayExecutor;
|
||||
import com.alibaba.cloud.dubbo.gateway.DubboCloudGatewayProperties;
|
||||
import com.alibaba.cloud.dubbo.gateway.autoconfigure.DubboCloudGatewayAutoConfiguration;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||
import org.springframework.cloud.gateway.route.RouteLocator;
|
||||
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.codec.ServerCodecConfigurer;
|
||||
import org.springframework.http.codec.support.DefaultServerCodecConfigurer;
|
||||
|
||||
/**
|
||||
* The Auto-{@link Configuration} of Dubbo Spring Cloud Gateway
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnClass(GlobalFilter.class)
|
||||
@ConditionalOnProperty(prefix = "dubbo.cloud.gateway", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@AutoConfigureAfter({ DubboServiceAutoConfiguration.class,
|
||||
DubboMetadataAutoConfiguration.class, DubboCloudGatewayAutoConfiguration.class })
|
||||
@EnableConfigurationProperties(DubboCloudGatewayProperties.class)
|
||||
public class DubboSpringCloudGatewayAutoConfiguration {
|
||||
|
||||
private final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(ServerCodecConfigurer.class)
|
||||
public ServerCodecConfigurer serverCodecConfigurer() {
|
||||
return new DefaultServerCodecConfigurer();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DubboSpringCloudGatewayFilter dubboSpringCloudGatewayFilter(
|
||||
DubboCloudGatewayExecutor dubboCloudGatewayExecutor) {
|
||||
return new DubboSpringCloudGatewayFilter(dubboCloudGatewayExecutor);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RouteLocator gatewayRoutes(RouteLocatorBuilder builder) {
|
||||
return builder.routes()
|
||||
.route(r -> r.path("/**").uri("http://localhost:9090").id("first"))
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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
|
||||
*
|
||||
* http://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.dubbo.gateway.standard;
|
||||
|
||||
import com.alibaba.cloud.dubbo.gateway.DubboCloudGatewayExecutor;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilter;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
||||
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
/**
|
||||
* The Spring Cloud {@link GatewayFilter Gateway Filter} for Dubbo
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
public class DubboSpringCloudGatewayFilter
|
||||
implements GatewayFilter, GlobalFilter, Ordered {
|
||||
|
||||
private final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private int order;
|
||||
|
||||
private final DubboCloudGatewayExecutor dubboCloudGatewayExecutor;
|
||||
|
||||
public DubboSpringCloudGatewayFilter(
|
||||
DubboCloudGatewayExecutor dubboCloudGatewayExecutor) {
|
||||
this.dubboCloudGatewayExecutor = dubboCloudGatewayExecutor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||
|
||||
Object result = dubboCloudGatewayExecutor.execute(exchange.getRequest());
|
||||
|
||||
if (result == null) {
|
||||
chain.filter(exchange);
|
||||
}
|
||||
else {
|
||||
ServerHttpResponse response = exchange.getResponse();
|
||||
}
|
||||
|
||||
return Mono.empty();
|
||||
}
|
||||
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.alibaba.cloud.dubbo.gateway.autoconfigure.DubboCloudGatewayAutoConfiguration,\
|
||||
com.alibaba.cloud.dubbo.gateway.standard.DubboSpringCloudGatewayAutoConfiguration
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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
|
||||
*
|
||||
* http://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.dubbo.gateway.standard;
|
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
|
||||
/**
|
||||
* The bootstrap class of Dubbo Spring Cloud Gateway
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
public class DubboSpringCloudGatewayBootstrap {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(DubboSpringCloudGatewayBootstrap.class)
|
||||
.properties("spring.profiles.active=zookeeper").run(args);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
spring:
|
||||
application:
|
||||
name: spring-cloud-alibaba-dubbo-gateway
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
|
||||
dubbo:
|
||||
protocols:
|
||||
dubbo:
|
||||
port: -1
|
||||
|
||||
server:
|
||||
port: 9090
|
||||
|
||||
# default disable all
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
enabled: false
|
||||
register-enabled: false
|
||||
zookeeper:
|
||||
enabled: false
|
||||
consul:
|
||||
enabled: false
|
||||
|
||||
eureka:
|
||||
client:
|
||||
enabled: false
|
||||
|
||||
|
||||
---
|
||||
spring:
|
||||
profiles: nacos
|
||||
|
||||
cloud:
|
||||
nacos:
|
||||
username: nacos
|
||||
password: nacos
|
||||
discovery:
|
||||
enabled: true
|
||||
register-enabled: true
|
||||
server-addr: 127.0.0.1:8848
|
||||
ephemeral: false
|
||||
|
||||
|
||||
---
|
||||
spring:
|
||||
profiles: eureka
|
||||
|
||||
eureka:
|
||||
client:
|
||||
enabled: true
|
||||
service-url:
|
||||
defaultZone: http://127.0.0.1:8761/eureka/
|
||||
|
||||
|
||||
---
|
||||
spring:
|
||||
profiles: zookeeper
|
||||
cloud:
|
||||
zookeeper:
|
||||
enabled: true
|
||||
connect-string: 127.0.0.1:2181
|
||||
|
||||
|
||||
---
|
||||
spring:
|
||||
profiles: consul
|
||||
|
||||
cloud:
|
||||
consul:
|
||||
enabled: true
|
||||
host: 127.0.0.1
|
||||
port: 8500
|
@ -22,6 +22,7 @@ import java.util.Set;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import static com.alibaba.cloud.dubbo.util.DubboCloudConstants.CONFIG_PROPERTY_PREFIX;
|
||||
import static org.springframework.util.StringUtils.commaDelimitedListToStringArray;
|
||||
import static org.springframework.util.StringUtils.hasText;
|
||||
import static org.springframework.util.StringUtils.trimAllWhitespace;
|
||||
@ -31,7 +32,7 @@ import static org.springframework.util.StringUtils.trimAllWhitespace;
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "dubbo.cloud")
|
||||
@ConfigurationProperties(prefix = CONFIG_PROPERTY_PREFIX)
|
||||
public class DubboCloudProperties {
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.dubbo.util;
|
||||
|
||||
/**
|
||||
* The constants for Dubbo Spring Cloud.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
public final class DubboCloudConstants {
|
||||
|
||||
private DubboCloudConstants() {
|
||||
throw new AssertionError("Must not instantiate constant utility class");
|
||||
}
|
||||
|
||||
/**
|
||||
* The property prefix of Configuration.
|
||||
*/
|
||||
public static final String CONFIG_PROPERTY_PREFIX = "dubbo.cloud";
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user