spring cloud搭建eureka+feign+gateway+zipkin

创建eureka+feign+gateway+zipkin

  • 1、创建两个eureka server
    • 1.1创建server1
      • 1.1.1pom文件
      • 1.1.2 创建application.yml
      • 1.1.3 启动类
      • 1.2.1 eureka server2 的pom文件
    • 1.2.2 创建server2 application.yml
      • 1.2.3 启动类
  • 2、创建两个eureka client
    • 2.1 创建client1
      • 2.1.1 创建client1 pom文件
      • 2.1.2 创建client1 application.yml
      • 2.1.3 创建client1 启动类
      • 2.1.4 创建client1 Conctroller
    • 2.2 创建client2
      • 2.2.2 创建client1 application.yml
      • 2.2.2 创建client2 Conctroller
  • 3、创建feign1
    • 3.1 创建feign1 pom文件
    • 3.2 创建feign1 application.yml
    • 3.3 创建feign1 启动类
    • 3.4 创建feign1 Feign类用于请求客户端
    • 3.5 创建feign1 Conctroller
    • 3.6 创建feign1 HystrixTest用于熔断,也可用注解
  • 4、创建gateway
    • 4.1 创建gateway pom
    • 4.2 创建gateway application.yml
    • 4.2 创建gateway 启动类
  • 5、创建zipkin
    • 5.1 创建zipkin pom
    • 5.2 创建zipkin application.yml
    • 5.3 创建zipkin 启动类

在host文件加上以下域名,注意以下feign是后边有1的

127.0.0.1 server1
127.0.0.1 server2
127.0.0.1 client
127.0.0.1 feign1
127.0.0.1 zipkin

1、创建两个eureka server

1.1创建server1

1.1.1pom文件

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <parent>
 	<groupId>org.springframework.boot</groupId>
 	<artifactId>spring-boot-starter-parent</artifactId>
 	<version>2.3.4.RELEASE</version>
 	<relativePath/>
 </parent>
 <groupId>com.example</groupId>
 <artifactId>eurekaserver</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <name>eurekaserver</name>
 <description>Demo project for Spring Boot</description>

 <properties>
 	<java.version>1.8</java.version>
 	<spring-cloud.version>Hoxton.SR8</spring-cloud.version>
 </properties>

 <dependencies>
 	<!-- 服务追踪 -->
 	<dependency>
 		<groupId>org.springframework.cloud</groupId>
 		<artifactId>spring-cloud-starter-zipkin</artifactId>
 	</dependency>
 	<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-test</artifactId>
 		<scope>test</scope>
 		<exclusions>
 			<exclusion>
 				<groupId>org.junit.vintage</groupId>
 				<artifactId>junit-vintage-engine</artifactId>
 			</exclusion>
 		</exclusions>
 	</dependency>
 </dependencies>

 <dependencyManagement>
 	<dependencies>
 		<dependency>
 			<groupId>org.springframework.cloud</groupId>
 			<artifactId>spring-cloud-dependencies</artifactId>
 			<version>${spring-cloud.version}</version>
 			<type>pom</type>
 			<scope>import</scope>
 		</dependency>
 	</dependencies>
 </dependencyManagement>

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

</project>

1.1.2 创建application.yml

spring:
  application:
    name: eureka-server
  zipkin:
    discovery-client-enabled: true
    baseUrl: http://zipkin:8061
    sender:
      type: web
  sleuth:
    sampler:
      probability: 1  # 设置抽样采集率为100%,默认为0.1,即10%,这里为了测试
server:
  port: 8089
eureka:
  instance:
    hostname: server1
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://server2:8088/eureka/
  server:
    enable-self-preservation: false #自我保护机制
    eviction-interval-timer-in-ms: 30000  #及时踢出已关停的节点


1.1.3 启动类

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {

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

}

spring cloud搭建eureka+feign+gateway+zipkin_第1张图片
启动eurekaserver后访问8089端口
spring cloud搭建eureka+feign+gateway+zipkin_第2张图片

1.2.1 eureka server2 的pom文件

两个服务applicattion的名称一样

spring:
  application:
    name: eureka-server
  zipkin:
    discovery-client-enabled: true
    baseUrl: http://zipkin:8061
    sender:
      type: web
  sleuth:
    sampler:
      probability: 1  # 设置抽样采集率为100%,默认为0.1,即10%,这里为了测试
server:
  port: 8088
eureka:
  instance:
    hostname: server2
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://server1:8089/eureka/
  server:
    enable-self-preservation: false #自我保护机制
    eviction-interval-timer-in-ms: 30000  #及时踢出已关停的节点


1.2.2 创建server2 application.yml

spring:
  application:
    name: eureka-server
  zipkin:
    discovery-client-enabled: true
    baseUrl: http://zipkin:8061
    sender:
      type: web
  sleuth:
    sampler:
      probability: 1  # 设置抽样采集率为100%,默认为0.1,即10%,这里为了测试
server:
  port: 8088
eureka:
  instance:
    hostname: server2
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://server1:8089/eureka/
  server:
    enable-self-preservation: false #自我保护机制
    eviction-interval-timer-in-ms: 30000  #及时踢出已关停的节点


1.2.3 启动类

@SpringBootApplication
@EnableEurekaServer
 public class EurekaServer2Application {

    public static void main(String[] args) {
        SpringApplication.run(EurekaServer2Application.class, args);
    }

}

启动eurekaserver2后访问8088端口
spring cloud搭建eureka+feign+gateway+zipkin_第3张图片

2、创建两个eureka client

2.1 创建client1

2.1.1 创建client1 pom文件

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.cl</groupId>
    <artifactId>eurekaclient1</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>eurekaclient1</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Hoxton.SR8</spring-cloud.version>
    </properties>

    <dependencies>
        <!-- 服务追踪 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zipkin</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

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

</project>

2.1.2 创建client1 application.yml

################ 项目基本配置 ################
server:
  port: 8011
  servlet:
    # 项目访问路径前缀
    context-path: /
spring:
  application:
    # 注册到Eureka的服务名
    name: clienttest
  zipkin:
    discovery-client-enabled: true
    baseUrl: http://zipkin:8061
    sender:
      type: web
  sleuth:
    sampler:
      probability: 1  # 设置抽样采集率为100%,默认为0.1,即10%,这里为了测试
 
################ Eureka配置 ################
eureka:
  client:
    service-url:
      defaultZone: http://server1:8089/eureka/,http://server2:8088/eureka/

2.1.3 创建client1 启动类

@SpringBootApplication
@EnableEurekaClient
public class Eurekaclient1Application {

    public static void main(String[] args) {
        SpringApplication.run(Eurekaclient1Application.class, args);
    }
    @Bean
    @LoadBalanced
    RestTemplate restTemplate() {
        return new RestTemplate();
    }
}

2.1.4 创建client1 Conctroller

@RestController
public class EurekaClientConctroller {
    @RequestMapping("/test")
    public String test(){
        return "i am Client1";
    }
}

spring cloud搭建eureka+feign+gateway+zipkin_第4张图片
启动client1后访问8088,显示已经有客户端注册
spring cloud搭建eureka+feign+gateway+zipkin_第5张图片

2.2 创建client2

2.2.2 创建client1 application.yml

其中pom和client1一样,只是设置了不同端口

################ 项目基本配置 ################
server:
  port: 8012
  servlet:
    # 项目访问路径前缀
    context-path: /
spring:
  application:
    # 注册到Eureka的服务名
    name: clienttest
  zipkin:
    discovery-client-enabled: true
    baseUrl: http://zipkin:8061
    sender:
      type: web
  sleuth:
    sampler:
      probability: 1  # 设置抽样采集率为100%,默认为0.1,即10%,这里为了测试
 
################ Eureka配置 ################
eureka:
  client:
    service-url:
      defaultZone: http://server1:8089/eureka/,http://server2:8088/eureka/

2.2.2 创建client2 Conctroller

@RestController
public class EurekaClientConctroller {
    @RequestMapping("/test")
    public String test(){
        return "i am Client2";
    }
}

启动client2,访问注册中心,显示client2已经注册
spring cloud搭建eureka+feign+gateway+zipkin_第6张图片

3、创建feign1

3.1 创建feign1 pom文件

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.fei</groupId>
    <artifactId>feign1</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>feign1</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Hoxton.SR8</spring-cloud.version>
    </properties>

    <dependencies>
        <!-- 服务追踪 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zipkin</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</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-starter-openfeign</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-netflix-eureka-client</artifactId>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

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

</project>

3.2 创建feign1 application.yml

server:
  port: 8085
eureka:
  client:
    serviceUrl:
      defaultZone: http://server1:8089/eureka/,http://server2:8088/eureka/

spring:
  application:
    name: feign1
  zipkin:
    discovery-client-enabled: true
    baseUrl: http://zipkin:8061/
    sender:
      type: web
  sleuth:
    sampler:
      probability: 1  # 设置抽样采集率为100%,默认为0.1,即10%,这里为了测试
feign:
  hystrix:
    enabled: true


3.3 创建feign1 启动类

package com.fei.feign1;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
@EnableCircuitBreaker
public class Feign1Application {

    public static void main(String[] args) {
        SpringApplication.run(Feign1Application.class, args);
    }
    @Bean
    @LoadBalanced
    RestTemplate RestTemplate() {
        return new RestTemplate();
    }
}

3.4 创建feign1 Feign类用于请求客户端

其中clienttest是client1和client2注册到Eureka的服务名

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;

@FeignClient(value = "clienttest")
public interface Feign {
    @RequestMapping(value = "/test")
     String test();
}

3.5 创建feign1 Conctroller

package com.fei.feign1;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;


@RestController
public class FeigntTestController {
    @Autowired
    Feign feign;
    @Autowired
    RestTemplate restTemplate;
    @GetMapping("/feignTest")
    @HystrixCommand(fallbackMethod = "error")
    public String getStr(){
        System.out.println(1111111111);
        return feign.test();
    }
    public String error(){
        return "errrrrr";
    }
    @GetMapping("/restTest")
    @HystrixCommand(fallbackMethod = "error")
    public String getTest(){
        System.out.println(123);
        return restTemplate.getForObject("http://clienttest/test",String.class);
    }
}

3.6 创建feign1 HystrixTest用于熔断,也可用注解

package com.fei.feign1;

import org.springframework.stereotype.Component;


@Component
public class HystrixTest implements Feign {
    @Override
    public String test() {
        return "error!!";
    }
}

spring cloud搭建eureka+feign+gateway+zipkin_第7张图片
启动后可以看到注册中心已有feign1
spring cloud搭建eureka+feign+gateway+zipkin_第8张图片
此时请求两次http://localhost:8085/feignTest会负载到两个client1和client2上
spring cloud搭建eureka+feign+gateway+zipkin_第9张图片

spring cloud搭建eureka+feign+gateway+zipkin_第10张图片

4、创建gateway

4.1 创建gateway pom

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.gateway</groupId>
    <artifactId>gateway</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>gateway</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Hoxton.SR8</spring-cloud.version>
    </properties>

    <dependencies>
        <!-- 服务追踪 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zipkin</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-gateway</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

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

</project>

4.2 创建gateway application.yml

spring:
  application:
    name: gateway
  zipkin:
    discovery-client-enabled: true
    baseUrl: http://zipkin:8061
    sender:
      type: web
  sleuth:
    sampler:
      probability: 1  # 设置抽样采集率为100%,默认为0.1,即10%,这里为了测试
server:
  port: 8070
  spring:
    cloud:
      gateway:
        routes:
          - id: 1
            uri: lb://feign1:8085
            predicates:
              - Path=/
eureka:
  instance:
    hostname: cloud-gateway-service
  client:
    serviceUrl:
      defaultZone: http://server1:8089/eureka/,http://server2:8088/eureka/

logging:
  level:
    # log 级别
    org.springframework.cloud.gateway: debug

4.2 创建gateway 启动类

package com.gateway.gateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EnableEurekaClient
public class GatewayApplication {

    public static void main(String[] args) {
        SpringApplication.run(GatewayApplication.class, args);
    }
    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route("path_route", r -> r.path("/feignTest")
                        .uri("http://feign1:8085"))
                .route("path_route", r -> r.path("/restTest")
                        .uri("http://feign1:8085"))
                .build();
    }

}


spring cloud搭建eureka+feign+gateway+zipkin_第11张图片
启动后再eureka上显示
spring cloud搭建eureka+feign+gateway+zipkin_第12张图片
http://localhost:8070/feignTest 或者http://localhost:8070/restTest
均可以返回
spring cloud搭建eureka+feign+gateway+zipkin_第13张图片

5、创建zipkin

5.1 创建zipkin pom

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project-name>zipkin-server</project-name>
        <spring-cloud.version>Finchley.SR2</spring-cloud.version>
        <zipkin.version>2.11.9</zipkin.version>
    </properties>

    <groupId>com.cloud</groupId>
    <artifactId>${project-name}</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>${project-name}</name>
    <description>${project-name}</description>

    <dependencies>
        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin-server</artifactId>
            <version>${zipkin.version}</version>
        </dependency>

        <!-- 使用消息的方式收集数据(使用rabbitmq)
        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin-autoconfigure-collector-rabbitmq</artifactId>
            <version>${zipkin.version}</version>
        </dependency>-->

        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin-autoconfigure-ui</artifactId>
            <version>2.11.9</version>
        </dependency>
        <!--eureka-client-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-test</artifactId>
            <version>2.3.4.RELEASE</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.3.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.3.0</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <!--依赖管理,用于管理spring-cloud的依赖,其中Camden.SR3是版本号-->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

</project>

5.2 创建zipkin application.yml

server:
  port: 8061
spring:
  application:
    name: zipkinserver2
eureka:
  instance:
    hostname: zipkin
  client:
    serviceUrl:
      defaultZone: http://server1:8089/eureka/,http://server2:8088/eureka/
management:
  metrics:
    web:
      server:
        auto-time-requests: false

5.3 创建zipkin 启动类

package com.example.zipkinserver2;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import zipkin2.server.internal.EnableZipkinServer;

@SpringBootApplication
@EnableEurekaClient
@EnableZipkinServer
public class Zipkinserver2Application {

    public static void main(String[] args) {
        SpringApplication.run(Zipkinserver2Application.class, args);
    }

}

spring cloud搭建eureka+feign+gateway+zipkin_第14张图片
启动后查看注册中心zipkin已经注册
spring cloud搭建eureka+feign+gateway+zipkin_第15张图片
请求http://localhost:8070/restTest后在请求zipkin服务http://localhost:8061
spring cloud搭建eureka+feign+gateway+zipkin_第16张图片
spring cloud搭建eureka+feign+gateway+zipkin_第17张图片
spring cloud搭建eureka+feign+gateway+zipkin_第18张图片

你可能感兴趣的:(spring,cloud,zipkin,java,eureka,spring,boot)