Skip to content

Commit e54ebb3

Browse files
committed
sample webflux
1 parent 8e5ccb4 commit e54ebb3

File tree

7 files changed

+282
-14
lines changed

7 files changed

+282
-14
lines changed

spring-cloud-gray-samples/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<module>spring-cloud-gray-gateway-sample</module>
2626
<module>spring-cloud-gray-consumer-nacos-config-sample</module>
2727
<module>spring-cloud-gray-apollo-config-sample</module>
28+
<module>spring-cloud-gray-service-a-webflux-sample</module>
2829
</modules>
2930

3031
<build>

spring-cloud-gray-samples/spring-cloud-gray-gateway-sample/pom.xml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
<groupId>org.springframework.boot</groupId>
2525
<artifactId>spring-boot-starter-test</artifactId>
2626
</dependency>
27-
<!-- <dependency>-->
28-
<!-- <groupId>org.springframework.cloud</groupId>-->
29-
<!-- <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>-->
30-
<!-- </dependency>-->
3127
<dependency>
32-
<groupId>com.alibaba.cloud</groupId>
33-
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
28+
<groupId>org.springframework.cloud</groupId>
29+
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
3430
</dependency>
31+
<!-- <dependency>-->
32+
<!-- <groupId>com.alibaba.cloud</groupId>-->
33+
<!-- <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>-->
34+
<!-- </dependency>-->
3535

3636

3737
<dependency>
@@ -55,16 +55,16 @@
5555
<artifactId>spring-cloud-gray-plugin-webmvc</artifactId>
5656
<groupId>cn.springcloud.gray</groupId>
5757
</exclusion>
58-
<exclusion>
59-
<groupId>cn.springcloud.gray</groupId>
60-
<artifactId>spring-cloud-gray-plugin-eureka</artifactId>
61-
</exclusion>
58+
<!-- <exclusion>-->
59+
<!-- <groupId>cn.springcloud.gray</groupId>-->
60+
<!-- <artifactId>spring-cloud-gray-plugin-eureka</artifactId>-->
61+
<!-- </exclusion>-->
6262
</exclusions>
6363
</dependency>
64-
<dependency>
65-
<groupId>cn.springcloud.gray</groupId>
66-
<artifactId>spring-cloud-gray-plugin-ribbon-nacos-discovery</artifactId>
67-
</dependency>
64+
<!-- <dependency>-->
65+
<!-- <groupId>cn.springcloud.gray</groupId>-->
66+
<!-- <artifactId>spring-cloud-gray-plugin-ribbon-nacos-discovery</artifactId>-->
67+
<!-- </dependency>-->
6868
<dependency>
6969
<groupId>cn.springcloud.gray</groupId>
7070
<artifactId>spring-cloud-gray-plugin-gateway</artifactId>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>spring-cloud-gray-samples</artifactId>
7+
<groupId>cn.springcloud.gray</groupId>
8+
<version>B.1.0.0-RC1</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>spring-cloud-gray-service-a-webflux-sample</artifactId>
13+
14+
<dependencies>
15+
<!-- <dependency>-->
16+
<!-- <groupId>org.springframework.boot</groupId>-->
17+
<!-- <artifactId>spring-boot-starter-web</artifactId>-->
18+
<!-- </dependency>-->
19+
<dependency>
20+
<groupId>org.springframework.boot</groupId>
21+
<artifactId>spring-boot-starter-webflux</artifactId>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.springframework.boot</groupId>
25+
<artifactId>spring-boot-starter-test</artifactId>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.springframework.cloud</groupId>
29+
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
30+
</dependency>
31+
<!-- <dependency>-->
32+
<!-- <groupId>com.alibaba.cloud</groupId>-->
33+
<!-- <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>-->
34+
<!-- </dependency>-->
35+
<dependency>
36+
<groupId>org.apache.commons</groupId>
37+
<artifactId>commons-lang3</artifactId>
38+
</dependency>
39+
<dependency>
40+
<groupId>com.google.guava</groupId>
41+
<artifactId>guava</artifactId>
42+
</dependency>
43+
44+
45+
<dependency>
46+
<groupId>cn.springcloud.gray</groupId>
47+
<artifactId>spring-cloud-starter-gray-client</artifactId>
48+
<exclusions>
49+
<exclusion>
50+
<groupId>cn.springcloud.gray</groupId>
51+
<artifactId>spring-cloud-gray-plugin-webmvc</artifactId>
52+
</exclusion>
53+
</exclusions>
54+
</dependency>
55+
<dependency>
56+
<groupId>cn.springcloud.gray</groupId>
57+
<artifactId>spring-cloud-gray-plugin-webflux</artifactId>
58+
</dependency>
59+
</dependencies>
60+
61+
<build>
62+
<plugins>
63+
<plugin>
64+
<!--skip deploy -->
65+
<artifactId>maven-deploy-plugin</artifactId>
66+
<configuration>
67+
<skip>true</skip>
68+
</configuration>
69+
</plugin>
70+
</plugins>
71+
</build>
72+
73+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package cn.springcloud.service.a;
2+
3+
import org.slf4j.LoggerFactory;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.boot.builder.SpringApplicationBuilder;
6+
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
7+
import org.springframework.core.env.Environment;
8+
9+
import java.net.InetAddress;
10+
import java.net.UnknownHostException;
11+
12+
/**
13+
* Created by saleson on 2017/10/18.
14+
*/
15+
@SpringBootApplication
16+
@EnableDiscoveryClient
17+
public class ServiceA2Application {
18+
private static final org.slf4j.Logger log = LoggerFactory.getLogger(ServiceA2Application.class);
19+
20+
21+
public static void main(String[] args) throws UnknownHostException {
22+
Environment env = new SpringApplicationBuilder(ServiceA2Application.class)
23+
// .web(WebApplicationType.REACTIVE)
24+
.run(args)
25+
.getEnvironment();
26+
log.info(
27+
"\n----------------------------------------------------------\n\t"
28+
+ "Application '{}' is running! Access URLs:\n\t" + "Local: \t\thttp://127.0.0.1:{}\n\t"
29+
+ "External: \thttp://{}:{}\n----------------------------------------------------------",
30+
env.getProperty("spring.application.name"), env.getProperty("server.port"),
31+
InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"));
32+
33+
String configServerStatus = env.getProperty("configserver.status");
34+
log.info(
35+
"\n----------------------------------------------------------\n\t"
36+
+ "Config Server: \t{}\n----------------------------------------------------------",
37+
configServerStatus == null ? "Not found or not setup for this application" : configServerStatus);
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package cn.springcloud.service.a.rest;
2+
3+
import com.google.common.collect.ImmutableMap;
4+
import org.apache.commons.lang.StringUtils;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.beans.factory.annotation.Value;
7+
import org.springframework.core.env.Environment;
8+
import org.springframework.web.bind.annotation.RequestMapping;
9+
import org.springframework.web.bind.annotation.RequestMethod;
10+
import org.springframework.web.bind.annotation.RequestParam;
11+
import org.springframework.web.bind.annotation.ResponseBody;
12+
13+
import java.util.Map;
14+
15+
/**
16+
* Created by saleson on 2017/10/18.
17+
*/
18+
//@RestController
19+
//@RequestMapping("/api/test")
20+
public class TestResource {
21+
22+
@Value("${test.sleepTime:50}")
23+
private long sleepTime = 50;
24+
25+
@Autowired
26+
Environment env;
27+
28+
@RequestMapping(value = "/get", method = RequestMethod.GET)
29+
@ResponseBody
30+
public Map<String, String> testGet(@RequestParam(value = "version", required = false) String version) {
31+
long start = System.currentTimeMillis();
32+
// try {
33+
// Thread.sleep(sleepTime);
34+
// } catch (InterruptedException e) {
35+
// }
36+
return ImmutableMap.of("test", "success.",
37+
"version", StringUtils.defaultIfEmpty(version, ""),
38+
"serverPort", env.getProperty("server.port"),
39+
"usedTime", String.valueOf(System.currentTimeMillis() - start));
40+
}
41+
42+
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package cn.springcloud.service.a.rest;
2+
3+
import com.google.common.collect.ImmutableMap;
4+
import org.apache.commons.lang.StringUtils;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.beans.factory.annotation.Value;
7+
import org.springframework.core.env.Environment;
8+
import org.springframework.web.bind.annotation.*;
9+
import reactor.core.publisher.Mono;
10+
11+
import java.util.Map;
12+
13+
@RestController
14+
@RequestMapping("/api/test")
15+
public class TestWebFluxResource {
16+
17+
@Value("${test.sleepTime:50}")
18+
private long sleepTime = 50;
19+
20+
@Autowired
21+
Environment env;
22+
23+
@RequestMapping(value = "/get", method = RequestMethod.GET)
24+
@ResponseBody
25+
public Mono<Map<String, String>> testGet(@RequestParam(value = "version", required = false) String version) {
26+
long start = System.currentTimeMillis();
27+
// try {
28+
// Thread.sleep(sleepTime);
29+
// } catch (InterruptedException e) {
30+
// }
31+
return Mono.just(ImmutableMap.of("test", "success.",
32+
"version", StringUtils.defaultIfEmpty(version, ""),
33+
"serverPort", env.getProperty("server.port"),
34+
"usedTime", String.valueOf(System.currentTimeMillis() - start)));
35+
}
36+
37+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
spring:
2+
application:
3+
name: service-a
4+
cloud:
5+
nacos:
6+
discovery:
7+
server-addr: 127.0.0.1:8848
8+
server:
9+
port: 20105
10+
eureka:
11+
client:
12+
register-with-eureka: true
13+
fetch-registry: true
14+
# region: sh
15+
# availability-zones:
16+
# sh: xuhui
17+
serviceUrl:
18+
defaultZone: http://localhost:20001/eureka/
19+
# xuhui: http://localhost:20001/eureka/
20+
instance:
21+
# instanceId: ${spring.cloud.client.ipAddress}:${spring.application.name}:${server.port}
22+
lease-renewal-interval-in-seconds: 10
23+
lease-expiration-duration-in-seconds: 30
24+
# prefer-ip-address: true
25+
metadata-map:
26+
version: v3
27+
# zone: gray3
28+
# instanceId: s
29+
# initial-status: starting
30+
31+
32+
gray:
33+
mock:
34+
enabled: true
35+
36+
enabled: true
37+
hystrix:
38+
enabled: true
39+
server:
40+
url: http://gray-Server
41+
loadbalanced: true
42+
retryable: true
43+
retryNumberOfRetries: 3
44+
client:
45+
event:
46+
longpolling: 60000
47+
runenv: web
48+
infosUpdateIntervalTimerInMs: 0
49+
infosInitializeDelayTimeInMs: 10000
50+
instance:
51+
grayEnroll: false
52+
grayEnrollDealyTimeInMs: 20000
53+
holdoutServer:
54+
enabled: false
55+
services:
56+
"service-a": starting
57+
request:
58+
track:
59+
enabled: true
60+
trackType: web
61+
definitionsUpdateIntervalTimerInMs: 10000
62+
definitionsInitializeDelayTimeInMs: 10000
63+
web:
64+
track-definitions:
65+
- name: HttpReceive
66+
path-patterns: /*
67+
exclude-path-patterns: /test/*
68+
# client:
69+
# instance:
70+
# grayEnroll: false #是否在启动后自动注册成灰度实例
71+
logging:
72+
level:
73+
cn:
74+
springcloud:
75+
gray: debug

0 commit comments

Comments
 (0)