Skip to content

Commit f1cfadb

Browse files
author
duozhilin
committed
添加多版本控制的zookeeper示例
1 parent 9105050 commit f1cfadb

File tree

17 files changed

+459
-0
lines changed

17 files changed

+459
-0
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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-mult-version-samples</artifactId>
7+
<groupId>cn.springcloud.gray</groupId>
8+
<version>1.0.2</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>spring-cloud-bamboo-service-a-samples</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-test</artifactId>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.springframework.cloud</groupId>
25+
<artifactId>spring-cloud-starter-eureka</artifactId>
26+
</dependency>
27+
</dependencies>
28+
29+
<build>
30+
<plugins>
31+
<plugin>
32+
<!--skip deploy -->
33+
<artifactId>maven-deploy-plugin</artifactId>
34+
<configuration>
35+
<skip>true</skip>
36+
</configuration>
37+
</plugin>
38+
</plugins>
39+
</build>
40+
</project>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package cn.springcloud.bamboo.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+
@SpringBootApplication
13+
@EnableDiscoveryClient
14+
public class BambooServiceCApplication {
15+
16+
private static final org.slf4j.Logger log = LoggerFactory.getLogger(BambooServiceCApplication.class);
17+
18+
19+
public static void main(String[] args) throws UnknownHostException {
20+
Environment env = new SpringApplicationBuilder(BambooServiceCApplication.class).web(true).run(args).getEnvironment();
21+
log.info(
22+
"\n----------------------------------------------------------\n\t"
23+
+ "Application '{}' is running! Access URLs:\n\t" + "Local: \t\thttp://127.0.0.1:{}\n\t"
24+
+ "External: \thttp://{}:{}\n----------------------------------------------------------",
25+
env.getProperty("spring.application.name"), env.getProperty("server.port"),
26+
InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"));
27+
28+
String configServerStatus = env.getProperty("configserver.status");
29+
log.info(
30+
"\n----------------------------------------------------------\n\t"
31+
+ "Config Server: \t{}\n----------------------------------------------------------",
32+
configServerStatus == null ? "Not found or not setup for this application" : configServerStatus);
33+
}
34+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package cn.springcloud.bamboo.service.a.web.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.core.env.Environment;
7+
import org.springframework.web.bind.annotation.*;
8+
9+
import java.util.Map;
10+
11+
/**
12+
* Created by saleson on 2017/10/18.
13+
*/
14+
@RestController
15+
@RequestMapping("/api/test")
16+
public class TestResource {
17+
@Autowired
18+
Environment env;
19+
20+
@RequestMapping(value = "/get", method = RequestMethod.GET)
21+
@ResponseBody
22+
public Map<String, String> testGet(@RequestParam(value = "version", required = false) String version) {
23+
return ImmutableMap.of("test", "success.", "version", StringUtils.defaultIfEmpty(version, ""), "serverPort", env.getProperty("server.port"));
24+
}
25+
26+
27+
@RequestMapping(value = "/post", method = RequestMethod.POST)
28+
@ResponseBody
29+
public Map<String, String> testPost(@RequestParam(value = "version", required = false) String version, @RequestBody String body) {
30+
return ImmutableMap.of(
31+
"test", "success.", "version", StringUtils.defaultIfEmpty(version, ""),
32+
"serverPort", env.getProperty("server.port"), "body", body);
33+
}
34+
35+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
spring:
2+
application:
3+
name: service-a
4+
server:
5+
port: 10101
6+
eureka:
7+
client:
8+
register-with-eureka: true
9+
fetch-registry: true
10+
serviceUrl:
11+
defaultZone: http://localhost:10001/eureka/
12+
instance:
13+
instanceId: ${spring.application.name}:${server.port}
14+
metadata-map:
15+
versions: 1,2
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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-mult-version-samples</artifactId>
7+
<groupId>cn.springcloud.gray</groupId>
8+
<version>1.0.2</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>spring-cloud-bamboo-service-b-samples</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-test</artifactId>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.springframework.cloud</groupId>
25+
<artifactId>spring-cloud-starter-eureka</artifactId>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.springframework.cloud</groupId>
29+
<artifactId>spring-cloud-starter-feign</artifactId>
30+
</dependency>
31+
32+
<dependency>
33+
<groupId>org.apache.commons</groupId>
34+
<artifactId>commons-lang3</artifactId>
35+
<version>3.5</version>
36+
</dependency>
37+
38+
<dependency>
39+
<groupId>cn.springcloud.gray</groupId>
40+
<artifactId>spring-cloud-starter-multi-version</artifactId>
41+
</dependency>
42+
</dependencies>
43+
44+
<build>
45+
<plugins>
46+
<plugin>
47+
<!--skip deploy -->
48+
<artifactId>maven-deploy-plugin</artifactId>
49+
<configuration>
50+
<skip>true</skip>
51+
</configuration>
52+
</plugin>
53+
</plugins>
54+
</build>
55+
56+
</project>

0 commit comments

Comments
 (0)