该项目主要有以下模块

  1. 注册服务中心eurekasever
  2. 配置中心configserver
  3. Client前端全部页面
  4. 网关服务gateway-zuul
  5. 分布式Springcloud sleuth链路追踪zipkin
  6. 消费者user
  7. 提供者menu,order
  8. aispringcloud-api

一、注册服务中心

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaServerApplication.class,args);
    }
}

pom.xml依赖文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>aispringclouddome</artifactId>
        <groupId>com.snowy.southwind</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>eurekaserver</artifactId>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
            <version>2.0.2.RELEASE</version>
        </dependency>
    </dependencies>

</project>

配置文件

server:
  port: 8761
eureka:
  client:
    register-with-eureka: false
    fetch-registry: false
    service-url:
      defaultZone: http://localhost:8761/eureka/

效果截图
在这里插入图片描述

二、配置中心configserver

pom.xml依赖文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>aispringclouddome</artifactId>
        <groupId>com.snowy.southwind</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>configServer</artifactId>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            <version>2.0.2.RELEASE</version>
        </dependency>
    </dependencies>

</project>

配置文件

server:
  port: 8002
spring:
  application:
    name: configserver
  profiles:
      active: native
  cloud:
    config:
      server:
        native:
          search-locations: classpath:/shared
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/
  instance:
    instance-id: config-8002
    prefer-ip-address: true

网关服务gateway-zuul

pom.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>aispringclouddome</artifactId>
        <groupId>com.snowy.southwind</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>allzuul</artifactId>

    <dependencies>
        <!--字配置中心-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-netflix-hystrix-dashboard</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zipkin</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
        </dependency>
    </dependencies>
</project>

配置文件

spring:
  application:
    name: allzuul
  profiles:
    active: dev
  cloud:
    config:
      uri: http://localhost:8002
      fail-fast: true


server:
  port: 8060
spring:
  application:
    name: allzuul
  zipkin:
    base-url: http://localhost:9009/
    sleuth:
      sampler:
        probability: 1.0
eureka:
  instance:
    instance-id: allzuul-8060
    prefer-ip-address: true
  client:
    lease-renewal-interval-in-seconds: 5
    lease-expiration-duration-in-seconds: 10
    service-url:
      defaultZone: http://localhost:8761/eureka/


#zuul:
#  routes:
#    eureka-ribbon: #对应服务名称,可以自定义(最好保持一致)
#     path: /ribbon/*
#     serviceId: eureka-ribbon #对应服务名称
#    eureka-feign:
#      path: /Takeaway/*
#      serviceId: allclient #对应服务名称
zuul:        #配置Zuul设置
  routes:
    allclient:
      path: /**    #Zuul路由的前缀
  host:       #超时设置
    socket-timeout-millis: 60000
    connect-timeout-millis: 10000

zuul与hystrix结合实现熔断
在这里插入图片描述
输入localhost:8060/login.html,输入正确账号,调用跳回8030的接口,说明网关调用成功
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

.分布式Springcloud sleuth链路追踪zipkin

pom.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>aispringclouddome</artifactId>
        <groupId>com.snowy.southwind</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>zipkin-server</artifactId>

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Greenwich.SR3</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin-server</artifactId>
            <version>2.11.8</version>
        </dependency>
        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin-autoconfigure-ui</artifactId>
            <version>2.11.8</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-autoconfigure</artifactId>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

配置文件

server:
  port: 9009
spring:
  application:
    name: zipkin-server
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/     #注册中心地址
management:
  metrics:
    web:
      server:
        auto-time-requests: false           #关闭自动收集web请求

实现效果
在这里插入图片描述
在这里插入图片描述

更多模块我就不一一演示了,有需要的可以进行下载

项目源码请点击先下载
https://download.csdn.net/download/weixin_46820017/18847816

更多需要请关注一下,一起学习前进

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐