(1)、在其pom引入起步依赖spring-cloud-starter-zipkin,代码如下:
<?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”>
4.0.0
com.riemann
microservice-sleuth-zipkin
0.0.1-SNAPSHOT
com.riemann
microservice-service-zipkin-hi
0.0.1-SNAPSHOT
microservice-service-zipkin-hi
service-zipkin-hi
org.springframework.boot
spring-boot-starter-web
org.springframework.cloud
spring-cloud-starter-zipkin
(2)、在其配置文件application.properties
指定zipkin server
的地址,通过配置spring.zipkin.base-url
指定:
通过引入spring-cloud-starter-zipkin依赖和设置spring.zipkin.base-url就可以了。
(3)、对外暴露接口:
package com.riemann.microserviceproviderservicehi;
import java.util.logging.Level;
import java.util.logging.Logger;
import brave.sampler.Sampler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@SpringBootApplication
@RestController
public class MicroserviceProviderServiceHiApplication {
public static void main(String[] args) {
SpringApplication.run(MicroserviceProviderServiceHiApplication.class, args);
}
private static final Logger l