File tree Expand file tree Collapse file tree 16 files changed +297
-0
lines changed
springboot-22-cloud-consumer
springboot-22-cloud-eureka
springboot-22-cloud-provider Expand file tree Collapse file tree 16 files changed +297
-0
lines changed Original file line number Diff line number Diff line change 1+ # *** SpringBoot-cloud***
2+
3+ # 测负载均衡将provider模块等换端口号后进行打包,使用java -jar 包名的方式启动
4+ # 如果需要使用idear进行负载测试,重新建立一个空的工程
Original file line number Diff line number Diff line change 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 >SpringBootLearn</artifactId >
7+ <groupId >com.clown</groupId >
8+ <version >1.0-SNAPSHOT</version >
9+ </parent >
10+ <modelVersion >4.0.0</modelVersion >
11+ <artifactId >springboot-22-cloud</artifactId >
12+ <packaging >pom</packaging >
13+ <modules >
14+ <module >springboot-22-cloud-eureka</module >
15+ <module >springboot-22-cloud-consumer</module >
16+ <module >springboot-22-cloud-provider</module >
17+ </modules >
18+ <repositories >
19+ <repository >
20+ <id >spring-milestones</id >
21+ <name >Spring Milestones</name >
22+ <url >https://repo.spring.io/milestone</url >
23+ </repository >
24+ </repositories >
25+ </project >
Original file line number Diff line number Diff line change 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 >springboot-22-cloud</artifactId >
7+ <groupId >com.clown</groupId >
8+ <version >1.0-SNAPSHOT</version >
9+ </parent >
10+ <modelVersion >4.0.0</modelVersion >
11+ <artifactId >springboot-22-cloud-consumer</artifactId >
12+
13+ <dependencies >
14+ <dependency >
15+ <groupId >org.springframework.cloud</groupId >
16+ <artifactId >spring-cloud-starter-netflix-eureka-client</artifactId >
17+ </dependency >
18+ </dependencies >
19+
20+ <dependencyManagement >
21+ <dependencies >
22+ <dependency >
23+ <groupId >org.springframework.cloud</groupId >
24+ <artifactId >spring-cloud-dependencies</artifactId >
25+ <version >Greenwich.RC2</version >
26+ <type >pom</type >
27+ <scope >import</scope >
28+ </dependency >
29+ </dependencies >
30+ </dependencyManagement >
31+ </project >
Original file line number Diff line number Diff line change 1+ package com .clown .consumer ;
2+
3+ import org .springframework .boot .SpringApplication ;
4+ import org .springframework .boot .autoconfigure .SpringBootApplication ;
5+ import org .springframework .cloud .client .discovery .EnableDiscoveryClient ;
6+
7+ /**
8+ * @author: Richard·Ackerman
9+ * @create: 2019/1/24
10+ **/
11+ @ EnableDiscoveryClient
12+ @ SpringBootApplication
13+ public class ConsumerApplication {
14+
15+ public static void main (String [] args ){
16+ SpringApplication .run (ConsumerApplication .class );
17+ }
18+ }
Original file line number Diff line number Diff line change 1+ package com .clown .consumer .config ;
2+
3+ import org .springframework .cloud .client .loadbalancer .LoadBalanced ;
4+ import org .springframework .context .annotation .Bean ;
5+ import org .springframework .context .annotation .Configuration ;
6+ import org .springframework .web .client .RestTemplate ;
7+
8+ /**
9+ * @author: Richard·Ackerman
10+ * @create: 2019/1/24
11+ **/
12+ @ Configuration
13+ public class MyConfig {
14+
15+ @ LoadBalanced //负载均衡机制
16+ @ Bean
17+ public RestTemplate restTemplate (){
18+ return new RestTemplate ();
19+ }
20+ }
Original file line number Diff line number Diff line change 1+ package com .clown .consumer .controller ;
2+
3+ import org .springframework .beans .factory .annotation .Autowired ;
4+ import org .springframework .web .bind .annotation .GetMapping ;
5+ import org .springframework .web .bind .annotation .RestController ;
6+ import org .springframework .web .client .RestTemplate ;
7+
8+ /**
9+ * @author: Richard·Ackerman
10+ * @create: 2019/1/24
11+ **/
12+ @ RestController
13+ public class ConsumerController {
14+
15+ @ Autowired
16+ private RestTemplate restTemplate ;
17+
18+ @ GetMapping ("/listen" )
19+ public String listen (){
20+ return restTemplate .getForObject ("http://provider/listen" ,String .class );
21+ }
22+ }
Original file line number Diff line number Diff line change 1+ server :
2+ port : 9999
3+ spring :
4+ application :
5+ name : consumer
6+ eureka :
7+ instance :
8+ prefer-ip-address : true
9+ client :
10+ service-url :
11+ defaultZone : http://localhost:8888/eureka/
Original file line number Diff line number Diff line change 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 >springboot-22-cloud</artifactId >
7+ <groupId >com.clown</groupId >
8+ <version >1.0-SNAPSHOT</version >
9+ </parent >
10+ <modelVersion >4.0.0</modelVersion >
11+ <artifactId >springboot-22-cloud-eureka</artifactId >
12+
13+ <dependencies >
14+ <dependency >
15+ <groupId >org.springframework.cloud</groupId >
16+ <artifactId >spring-cloud-starter-netflix-eureka-server</artifactId >
17+ </dependency >
18+ </dependencies >
19+
20+ <dependencyManagement >
21+ <dependencies >
22+ <dependency >
23+ <groupId >org.springframework.cloud</groupId >
24+ <artifactId >spring-cloud-dependencies</artifactId >
25+ <version >Greenwich.RC2</version >
26+ <type >pom</type >
27+ <scope >import</scope >
28+ </dependency >
29+ </dependencies >
30+ </dependencyManagement >
31+
32+ </project >
Original file line number Diff line number Diff line change 1+ package com .clown .eureka ;
2+
3+ import org .springframework .boot .SpringApplication ;
4+ import org .springframework .boot .autoconfigure .SpringBootApplication ;
5+ import org .springframework .cloud .netflix .eureka .server .EnableEurekaServer ;
6+
7+ /**
8+ * @author: Richard·Ackerman
9+ * @create: 2019/1/24
10+ **/
11+ //服务注册中心
12+ @ EnableEurekaServer
13+ @ SpringBootApplication
14+ public class EurekaApplication {
15+ public static void main (String [] args ){
16+ SpringApplication .run (EurekaApplication .class );
17+ }
18+ }
Original file line number Diff line number Diff line change 1+ server :
2+ port : 8888
3+ eureka :
4+ instance :
5+ hostname : eureka # 主机名称
6+ client :
7+ register-with-eureka : false # 是否将自己本身注册到注册中心,做集群式需要改为true
8+ fetch-registry : false # 不从eureka上获取服务的注册信息
9+ service-url :
10+ defaultZone : http://localhost:8888/eureka/ # 注册中心向外暴露ip
You can’t perform that action at this time.
0 commit comments