/spring-cloud-demo

Spring Cloud 简单案例:服务注册发现、网关、熔断、负载

Primary LanguageJava

Spring Cloud 基础案例

案例集成了Eureka、Zuul、OpenFeign、Zipkin、Hystrix等SpringCloud组件和基本使用方法。

Dependencies

  • spring boot parent
<parent>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-parent</artifactId>
	<version>2.1.3.RELEASE</version>
	<relativePath/> <!-- lookup parent from repository -->
</parent>
  • spring cloud
<dependencyManagement>
	<dependencies>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-dependencies</artifactId>
			<version>Greenwich.RELEASE</version>
			<type>pom</type>
			<scope>import</scope>
			</dependency>
	</dependencies>
</dependencyManagement>

运行项目

mvn package
java -jar eureka-server/target/eureka-server-2.1.0.jar
java -jar api-gateway/target/api-gateway-2.1.0.jar
java -jar open-feign/target/open-feign-2.1.0.jar
java -jar service-A/target/service-A-2.1.0.jar

Eureka Server

http://localhost:1111/

eureka server

Zuul

http://localhost:5555/api-a?a=1&b=2

openfeign

http://localhost:2300/?a=1&b=2

Zipkin链路追踪

curl -sSL https://zipkin.io/quickstart.sh | bash -s
java -jar zipkin.jar

http://localhost:9411

zipkin

Hystrix

http://127.0.0.1:5555/hystrix

配置 http://127.0.0.1:5555/hystrix.stream

Hystrix

功能介绍

  • 1.服务注册和发现
  • 2.api-gateway 认证,负载,熔断。具体参考 项目中的配置文件
  • 3.service 服务,基本的运算

参考地址