spring-cloud-demo demo地址:https://gitee.com/zkane/spring-cloud-demo
每个module里的README.md有详细的使用指南
org.springframework.boot
spring-boot-starter-jdbc
项目基于springboot2.0.3和springcloud Finchley
4.0.0
com.zkane
spring-cloud-demo
1.0.0
pom
org.springframework.boot
spring-boot-starter-parent
2.0.3.RELEASE
UTF-8
UTF-8
1.8
2.6.0
org.springframework.cloud
spring-cloud-dependencies
Finchley.RELEASE
pom
import
io.springfox
springfox-swagger2
${swagger.version}
io.springfox
springfox-swagger-ui
${swagger.version}
eureka-server
producer-server
consumer-server
config-server
config-client
zuul-server
auth-server
hystrix-dashboard
turbine
org.springframework.boot
spring-boot-maven-plugin
com.zkane
spring-cloud-demo
1.0.0
org.springframework.cloud
spring-cloud-starter-netflix-eureka-server
org.springframework.boot
spring-boot-starter-test
test
server:
port: 8000
spring:
application:
name: eureka-server
eureka:
client:
# 表示是否将自己注册到Eureka Server,默认为true。
register-with-eureka: false
# 表示是否从Eureka Server获取注册信息,默认为true。
fetch-registry: false
# 设置与Eureka Server交互的地址,查询服务和注册服务都需要依赖这个地址。默认是http://localhost:8761/eureka ;多个地址可使用,分隔
service-url:
defaultZone: http://localhost:${server.port}/eureka/
package com.zkane;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
4.0.0
com.zkane
producer-server
1.0.0
jar
producer-server
Spring Cloud Producer Server
com.zkane
spring-cloud-demo
1.0.0
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-test
test
server:
port: 8100
spring:
application:
name: producer-server
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8000/eureka/
package com.zkane;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@EnableDiscoveryClient
@SpringBootApplication
public class ProducerServerApplication {
public static void main(String[] args) {
SpringApplication.run(ProducerServerApplication.class, args);
}
}
package com.zkane.controller;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author: [email protected]
* @date: 2018/5/8
*/
@RestController
public class ProducerController {
@Value("${server.port}")
private String port;
@GetMapping("/get")
public String getPort() {
return "Producer Server port: " + port;
}
}
4.0.0
com.zkane
consumer-server
1.0.0
jar
consumer-server
Spring Cloud Consumer Server
com.zkane
spring-cloud-demo
1.0.0
org.springframework.boot
spring-boot-starter-web
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
org.springframework.cloud
spring-cloud-starter-openfeign
org.springframework.boot
spring-boot-starter-test
test
server:
port: 8200
spring:
application:
name: consumer-server
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8000/eureka/
feign:
hystrix:
enabled: true
package com.zkane;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
@EnableDiscoveryClient
@EnableFeignClients
@SpringBootApplication
public class ConsumerServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConsumerServerApplication.class, args);
}
}
package com.zkane.remote;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
/**
* @author: [email protected]
* @date: 2018/5/8
*/
@Component
@FeignClient(value = "producer-server", fallback = ProducerRemoteHystrix.class)
public interface ProducerRemote {
@GetMapping("/get")
String getPort();
}
feign:
hystrix:
enabled: true
@FeignClient(value = "producer-server", fallback = ProducerRemoteHystrix.class)
package com.zkane.remote;
import org.springframework.stereotype.Component;
/**
* @author: [email protected]
* @date: 2018/5/8
*/
@Component
public class ProducerRemoteHystrix implements ProducerRemote {
@Override
public String getPort() {
return "Producer Server 的服务调用失败";
}
}
curl -sSL https://zipkin.io/quickstart.sh | bash -s
java -jar zipkin.jar
http://localhost:9411/zipkin
org.springframework.cloud
spring-cloud-starter-sleuth
org.springframework.cloud
spring-cloud-starter-zipkin
spring:
zipkin:
base-url: http://localhost:9411/